如何在行更新事件中访问某些行数据绑定函数

时间:2012-05-01 07:58:56

标签: c# asp.net

我在行数据绑定事件中有这段代码:

 if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit)
    {
        string CCC = (string)DataBinder.Eval(e.Row.DataItem, "COLUMN");
        DropDownList DropDownList1 = (DropDownList)e.Row.FindControl("DropDownList1");
    }

如何使代码在行更新事件中起作用。 我想在没有if条件的情况下仅添加rowupdating事件。

string CCC = (string)DataBinder.Eval(e.Row.DataItem, "COLUMN");
            DropDownList DropDownList1 = (DropDownList)e.Row.FindControl("DropDownList1");

1 个答案:

答案 0 :(得分:0)

这里由Iam展示示例...用于SQL数据适配器更新...这也是我从这个StackOverFlow中学到的。

private static void OnRowUpdating(object sender, SqlRowUpdatingEventArgs e)
{
string MyERowValu = e.Row["sl_no"].ToString().Trim();
if (e.Row["itm_description"].ToString().Trim().Length == 0)
{
//e.Status = UpdateStatus.SkipCurrentRow;
e.Status = UpdateStatus.SkipAllRemainingRows;
}
}

我在Data_Save区域中使用的Bleow代码......

SQLCon.Open();

blah...blah...blah...blah...

SqlTransaction Trans1 = MyItmDatas.WMSCon.BeginTransaction();

MyDataAdapter1.UpdateCommand.Transaction = Trans1;
MyDataAdapter1.InsertCommand.Transaction = Trans1;
MyDataAdapter1.RowUpdating += new SqlRowUpdatingEventHandler(OnRowUpdating);

MyDataAdapter1.RowUpdating += new SqlRowUpdatingEventHandler(OnRowUpdating);

myDataGrid1.CurrentCell = myDataGrid1.FirstDisplayedCell;
myDataGrid1.EndEdit();

try
{
MyDataAdapter1.Update(ItemTable);
Trans1.Commit();
MessageBox.Show(" ITEMS UPDATED TO ....... ITEM MASTER ", " ITEM MASTER UPDATE ");
}
catch (Exception ex)
{
if (Trans1 != null)
{
Trans1.Rollback();
}
MessageBox.Show(ex.Message, "Item Master Save", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
SQLCon.Close();
MyDataAdapter1.RowUpdating -= new SqlRowUpdatingEventHandler(OnRowUpdating);
myDataGrid1.Refresh();