在gridview中找不到标签的控制权 [英] not find control on lable in gridview
本文介绍了在gridview中找不到标签的控制权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
protected void btnGvOrdSubmit_Click(对象发件人,EventArgs e)
{
foreach (GridViewRow行 in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
标签产品=(标签)row.FindControl( lblProduct);
Label ProductID =(Label)row.FindControl( lblProduct_Id);
标签价格=(标签)row.FindControl( Unit_Price) ;
TextBox Quanty =(TextBox)row.FindControl( txtQuantity);
标签总数=(标签)row.FindControl( lblTotal) ;
SqlConnection con = new SqlConnection(StrConnection);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText =
插入Order_Table(Product_Id,Quantity,Total_Price)值(@产品,@ Quanty,@ Total_Price);
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.Add( @ Product,SqlDbType.Char, 20 , Product_Id)。Value = ProductID。文本;
cmd.Parameters.AddWithValue( @ Quanty,Quanty.Text);
cmd.Parameters.AddWithValue( @ Total_Price,Total.Text);
cmd.ExecuteNonQuery();
}
}
}
标签总数=(标签)row.FindControl( lblTotal);我b
在这里我证明我的总价值可以通过乘法自动生成
价格*数量
请帮助
和thanx in adv。解决方案
你必须使用GridView1_RowDataBound事件&使用页脚计算总数。
请参阅下面的链接,在此帮助下您可以获得所需的解决方案
http://www.ezzylearning.com/tutorial/displaying-total-格栅内页 [ ^ ]
希望这会对你有所帮助。
谢谢
我认为你在页脚模板中使用了Total标签..
所以你必须在数据行中检查页脚不是..
赞了这个..
if (row.RowType == DataControlRowType.Footer)
{
标签总数=(标签)row.FindControl( lblTotal);
}
protected void btnGvOrdSubmit_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
Label Product = (Label)row.FindControl("lblProduct");
Label ProductID = (Label)row.FindControl("lblProduct_Id");
Label price = (Label)row.FindControl("Unit_Price");
TextBox Quanty = (TextBox)row.FindControl("txtQuantity");
Label Total = (Label)row.FindControl("lblTotal");
SqlConnection con = new SqlConnection(StrConnection);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText =
"insert into Order_Table(Product_Id,Quantity,Total_Price ) values(@Product,@Quanty,@Total_Price) ";
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.Add("@Product", SqlDbType.Char, 20, "Product_Id").Value = ProductID.Text;
cmd.Parameters.AddWithValue("@Quanty", Quanty.Text);
cmd.Parameters.AddWithValue("@Total_Price", Total.Text);
cmd.ExecuteNonQuery();
}
}
}
Label Total = (Label)row.FindControl("lblTotal");
gridview not find control on total when i save my grid view data in dataBase
here i justify my total value auto generate on lable by multiply
price *Quantity
please help
and thanx in adv.
解决方案 Hi, you have to use GridView1_RowDataBound event & use footer to calculate total.
See below the link, whith the help of which you can get your required solution
http://www.ezzylearning.com/tutorial/displaying-total-in-footer-of-gridview[^]
Hope this will help you.
Thanks
i think you used the Total label in the footer template..
so you have to check in the Footer Not in the data Row..
Like This..
if (row.RowType == DataControlRowType.Footer)
{
Label Total = (Label)row.FindControl("lblTotal");
}
这篇关于在gridview中找不到标签的控制权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文