0

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

 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");
4

1 回答 1

0

Here by Iam showing the sample...for SQL Data Adapter Update...This also I learned from this StackOverFlow only.

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;
}
}

The Bleow Codes I used in Data_Save Areas...

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();
于 2012-05-01T08:34:15.157 回答