[英]How to access some row databound functions in row updating event
我在行數據綁定事件中有以下代碼:
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");
}
如何使代碼在行更新事件中工作。 我只想在rowupdating事件中添加此代碼,而不添加if條件。
string CCC = (string)DataBinder.Eval(e.Row.DataItem, "COLUMN");
DropDownList DropDownList1 = (DropDownList)e.Row.FindControl("DropDownList1");
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 Areas中使用的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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.