本文介绍了无法在网格视图中找到行索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好bros ....
i有一个网格视图..
按钮点击我要输入一些行数据其中r通过复选框检查..
为此我写代码...
hello bros....
i have a grid view..
on button click i want to enter some data of lines which r checked by check box..
for this i write the code...
string str;
protected void Button2_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvr in GridView1.Rows)
{
int rrowindx= gvr.RowIndex;
CheckBox cbb = (CheckBox)GridView1.Rows[rrowindx].Cells[6].Controls[1];
TextBox txt = (TextBox)GridView1.Rows[rrowindx].Cells[6].Controls[2];
==============================================================================
str= GridView1.Rows[rrowindx].Cells[0].Text.ToString();
//this 'str ' not returning any value.
==============================================================================
if(cbb.Checked)
{
SqlConnection con = new SqlConnection("Data Source=GAURAV-PC\\SQLEXPRESS;Initial Catalog=mydatabase;Integrated Security=True");
cmd = con.CreateCommand();
cmd.CommandText = "execute this @Eid,@txtvalue";
cmd.Parameters.Add("@Eid", SqlDbType.Int).Value = str;
cmd.Parameters.Add("@txtvalue", SqlDbType.VarChar).Value = txt.Text;
}}
}
**** ****没有值进入str ..这是ma问题
******** there is no value coming in str..this is ma problem
推荐答案
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox cbb = (CheckBox)gvr.Cells[6].Controls[1];
if (cbb.Checked)
{
TextBox txt = (TextBox)gvr.Cells[6].Controls[2];
string str = ((System.Web.UI.DataBoundLiteralControl)(gvr.Cells[0].Controls[0])).Text;
SqlConnection con = new SqlConnection("Data Source=GAURAV-PC\\SQLEXPRESS;Initial Catalog=mydatabase;Integrated Security=True");
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "execute this @Eid,@txtvalue";
cmd.Parameters.Add("@Eid", SqlDbType.Int).Value = str;
cmd.Parameters.Add("@txtvalue", SqlDbType.VarChar).Value = txt.Text;
}
}
这篇关于无法在网格视图中找到行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!