ASPxGridView和Linq常用总结(1)

2018-09-06 11:04

阅读:561

  实现目标: 焦点变更、后台cs页面得到选中行的值、新增和编辑一行时赋值方法

  1、焦点变更事件。向服务器查询聚焦行的 "ID" 和 "name" 信息,并该信息将返回到 OnGetRowValues() 函数

  //js页面

  function OnGridFocusedRowChanged() {
grid.GetRowValues(grid.GetFocusedRowIndex(), "ID";"name", OnGetRowValues);
}
// 处理服务器端传回的数据(values是个数组,包含 "ID" 和 "name" 值)
function OnGetRowValues(values) {
var key = values[0];

   if (key != null) {
gridView.PerformCallback(key);
} }

  //cs页面

  protected void gridView_CustomCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs e)
{
if (e.Parameters!="")
{
LinqDateSource1.Where = "ID ==\"" + e.Parameters + "\"";

}
LinqDateSource1.DataBind();
gridView.DataBind();
gridView.FocusedRowIndex = -1;
}

  //grid源中
<ClientSideEvents FocusedRowChanged="function(s, e) { OnGridFocusedRowChanged(); }"/>

  2、后台cs页面得到选中行的值

  int id = Convert.ToInt32(grdDriver.GetRowValues(grdDriver.FocusedRowIndex, "DriverID"));

  string name = grdDriver.GetRowValues(grdDriver.FocusedRowIndex, "DriverName").ToString();

  3、新增一行时赋值

  protected void grdDriverFee_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
{
int id = Convert.ToInt32(grdDriver.GetRowValues(grdDriver.FocusedRowIndex, "DriverID"));
string name = grdDriver.GetRowValues(grdDriver.FocusedRowIndex, "DriverName").ToString();

   e.NewValues["FeeTypeID"] = 1;
e.NewValues["ChkAudit"] = "0";
e.NewValues["DriverID"] = id;
e.NewValues["DriverName"] = name;
}

  4、编辑事件
protected void grid_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)

  
摘自 SYZ_YUMEIZHOU_YY


评论


亲,登录后才可以留言!