Asp.net的Gridview中的行更新 [英] Row update in Gridview of Asp.net
本文介绍了Asp.net的Gridview中的行更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Gridview中使用Row_updating事件进行编辑行,但是看起来我很麻烦,我在GridView中有多行,但我想只更新所选行,这里是我的编码
i am working in Gridview for edit rows, with Row_updating event, but it seems me a trouble, i have more than one rows in GridView but i want to update only selected row here is my coding
protected void GvGRN_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
Label GrnNo = (Label)GvGRN.Rows[e.RowIndex].FindControl("lblGRN");
TextBox GrnDate = (TextBox)GvGRN.Rows[e.RowIndex].FindControl("TxtGrnDate");
DropDownList ProCode = (DropDownList)GvGRN.Rows[e.RowIndex].FindControl("CmbProCode");
Label ProName = (Label)GvGRN.Rows[e.RowIndex].FindControl("lblProduct");
Label TagNo = (Label)GvGRN.Rows[e.RowIndex].FindControl("lblTagNo");
Label Unit = (Label)GvGRN.Rows[e.RowIndex].FindControl("lblUnit");
Label OpBal = (Label)GvGRN.Rows[e.RowIndex].FindControl("lblOpening");
TextBox QtyRec = (TextBox)GvGRN.Rows[e.RowIndex].FindControl("Txtreceive");
Label CloBal = (Label)GvGRN.Rows[e.RowIndex].FindControl("lblClosing");
Label Meters = (Label)GvGRN.Rows[e.RowIndex].FindControl("lblMeters");
StrSQL = "Update GRN Set";
StrSQL = StrSQL + " TagNo = '" + TagNo.Text + "',";
StrSQL = StrSQL + " ProductCode = '" + ProCode.Text + "',";
StrSQL = StrSQL + " OpeningBal = " + OpBal.Text + ",";
StrSQL = StrSQL + " Quantity = " + QtyRec.Text + ",";
StrSQL = StrSQL + " ClosingBal = " + CloBal.Text + "";
StrSQL = StrSQL + " Where GrnNo = '" + GrnNo.Text + "'";
MethodClass.ConnectionToQueryCommand(StrSQL, "ExecuteNonQuery");
}
plz帮助我,如果在这里使用任何编码逻辑
plz help me, if any coditional logic is used here
推荐答案
protected void GvGRN_RowUpdating(对象发送者,GridViewUpdateEventArgs e)
{
尝试
{
Label GrnNo =(Label)GvGRN .Rows [e.RowIndex] .FindControl(lblGRN);
TextBox GrnDate =(TextBox)GvGRN.Rows [e.RowIndex] .FindControl(TxtGrnDate);
DropDownList ProCode =(DropDownList)GvGRN.Rows [e.RowIndex] .FindControl(CmbProCode);
Label ProName =(Label)GvGRN.Rows [e.RowIndex] .FindControl( lblProduct);
Label TagNo =(Label)GvGRN.Rows [e.RowIndex] .FindControl(lblTagNo);
标签单位=(标签)GvGRN .Rows [e.RowIndex] .FindControl(lblUnit);
Label OpBal =(Label)GvGRN.Rows [e.RowIndex] .FindControl(lblOpening);
TextBox QtyRec =(TextBox)GvGRN.Rows [e.RowIndex] .FindControl(Txtreceive);
Label CloBal =(Label)GvGRN.Rows [e.RowIndex] .FindControl(lblClosing );
Label Meters =(Label)GvGRN.Rows [e.RowIndex] .FindControl(lblMeters);
StrSQL =Update GrnHead Set;
StrSQL = StrSQL +GrnDate ='+ GrnDate.Text +';
StrSQL = StrSQL +Where GrnNo ='+ GrnNo.Text +' ;
MethodClass.ConnectionToQueryCommand(StrSQL,ExecuteNonQuery);
StrSQL =从GRN中删除;
StrSQL = StrSQL +Where GrnNo ='+ GrnNo.Text +';
MethodClass.ConnectionToQueryCommand(StrSQL,ExecuteNonQuery);
for(var w = 0; w< = GvGRN.Rows.Count - 1; w ++)
{
if(GvGRN.Rows [w] == GvGRN.Rows [e.RowIndex])
{
StrSQL =插入GRN(GrnNo,TagNo,ProductCode,OpeningBal,Quantity,closingBal);
StrSQL = StrSQL +Values(;
StrSQL = StrSQL +'+ GrnNo.Text +',;
StrSQL = StrSQL +'+ TagNo.Text +',;
StrSQL = StrSQL +'+ ProCode.Text +',;
StrSQL = StrSQL ++ OpBal.Text +,;
StrSQL = StrSQL ++ QtyRec.Text +,;
StrSQL = StrSQL ++ CloBal.Text +);
MethodClass.ConnectionToQueryCommand(StrSQL ,ExecuteNonQuery);
}
else
{
string Tag =(GvGRN.Rows [w] .FindControl(lblTagNo)as Label).Text;
string PrCode =(GvGRN.Rows [W] .FindControl(lblCode)as Label).Text;
string OBal =(GvGRN.Rows [w] .FindControl(lblOpening)as Label).Text;
string QRec =(GvGRN.Rows [w] .FindControl(lblReceive)as Label).Text;
string CBal =(GvGRN.Rows [w] .FindControl(lblClosing)作为标签)。文本;
StrSQL =插入GRN(GrnNo,TagNo,ProductCode,OpeningBal,Quantity,closingBal);
StrSQL = StrSQL +值(;
StrSQL = StrSQL +'+ GrnNo.Text +',;
StrSQL = StrSQL +' + Tag +',;
StrSQL = StrSQL +'+ PrCode +',;
Str SQL = StrSQL ++ OBal +,;
StrSQL = StrSQL ++ QRec +,;
StrSQL = StrSQL ++ CBal +);
MethodClass.ConnectionToQueryCommand(StrSQL,ExecuteNonQuery);
}
}
protected void GvGRN_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
Label GrnNo = (Label)GvGRN.Rows[e.RowIndex].FindControl("lblGRN");
TextBox GrnDate = (TextBox)GvGRN.Rows[e.RowIndex].FindControl("TxtGrnDate");
DropDownList ProCode = (DropDownList)GvGRN.Rows[e.RowIndex].FindControl("CmbProCode");
Label ProName = (Label)GvGRN.Rows[e.RowIndex].FindControl("lblProduct");
Label TagNo = (Label)GvGRN.Rows[e.RowIndex].FindControl("lblTagNo");
Label Unit = (Label)GvGRN.Rows[e.RowIndex].FindControl("lblUnit");
Label OpBal = (Label)GvGRN.Rows[e.RowIndex].FindControl("lblOpening");
TextBox QtyRec = (TextBox)GvGRN.Rows[e.RowIndex].FindControl("Txtreceive");
Label CloBal = (Label)GvGRN.Rows[e.RowIndex].FindControl("lblClosing");
Label Meters = (Label)GvGRN.Rows[e.RowIndex].FindControl("lblMeters");
StrSQL = " Update GrnHead Set";
StrSQL = StrSQL + " GrnDate = '" + GrnDate.Text + "'";
StrSQL = StrSQL + " Where GrnNo = '" + GrnNo.Text + "'";
MethodClass.ConnectionToQueryCommand(StrSQL, "ExecuteNonQuery");
StrSQL = " Delete from GRN";
StrSQL = StrSQL + " Where GrnNo = '" + GrnNo.Text + "'";
MethodClass.ConnectionToQueryCommand(StrSQL, "ExecuteNonQuery");
for (var w = 0; w <= GvGRN.Rows.Count - 1; w++)
{
if (GvGRN.Rows[w] == GvGRN.Rows[e.RowIndex])
{
StrSQL = "insert into GRN(GrnNo,TagNo,ProductCode,OpeningBal,Quantity,closingBal)";
StrSQL = StrSQL + "Values(";
StrSQL = StrSQL + "'" + GrnNo.Text + "',";
StrSQL = StrSQL + "'" + TagNo.Text + "',";
StrSQL = StrSQL + "'" + ProCode.Text + "',";
StrSQL = StrSQL + "" + OpBal.Text + ",";
StrSQL = StrSQL + "" + QtyRec.Text + ",";
StrSQL = StrSQL + "" + CloBal.Text + ")";
MethodClass.ConnectionToQueryCommand(StrSQL, "ExecuteNonQuery");
}
else
{
string Tag = (GvGRN.Rows[w].FindControl("lblTagNo") as Label).Text;
string PrCode = (GvGRN.Rows[w].FindControl("lblCode") as Label).Text;
string OBal = (GvGRN.Rows[w].FindControl("lblOpening") as Label).Text;
string QRec = (GvGRN.Rows[w].FindControl("lblReceive") as Label).Text;
string CBal = (GvGRN.Rows[w].FindControl("lblClosing") as Label).Text;
StrSQL = "insert into GRN(GrnNo,TagNo,ProductCode,OpeningBal,Quantity,closingBal)";
StrSQL = StrSQL + "Values(";
StrSQL = StrSQL + "'" + GrnNo.Text + "',";
StrSQL = StrSQL + "'" + Tag + "',";
StrSQL = StrSQL + "'" + PrCode + "',";
StrSQL = StrSQL + "" + OBal + ",";
StrSQL = StrSQL + "" + QRec + ",";
StrSQL = StrSQL + "" + CBal + ")";
MethodClass.ConnectionToQueryCommand(StrSQL, "ExecuteNonQuery");
}
}
这篇关于Asp.net的Gridview中的行更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文