如何获取gridview中选中行的索引值
展开全部
GridView1.Rows[i].cell[0]
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
Label Biglbl = new Label();//LabelBig
Biglbl = (Label)GridView1.Rows[i].FindControl("LabelBig");
int _LidBig = int.Parse(Biglbl.Text);
string queryBig = "select CategoryBig_Id, CategoryBig_Name from Category_Big where CategoryBig_Id=" + _LidBig;
string connectionString = ConfigurationManager.ConnectionStrings["SuoMaWDataConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connectionString);
myConnection.Open();
SqlCommand CmdBig = new SqlCommand(queryBig, myConnection);
SqlDataReader Bigmm = CmdBig.ExecuteReader();
if (Bigmm.Read())
{
Biglbl.Text = Bigmm["CategoryBig_Name"].ToString().Trim();
}
}
希望可以帮助你。
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
Label Biglbl = new Label();//LabelBig
Biglbl = (Label)GridView1.Rows[i].FindControl("LabelBig");
int _LidBig = int.Parse(Biglbl.Text);
string queryBig = "select CategoryBig_Id, CategoryBig_Name from Category_Big where CategoryBig_Id=" + _LidBig;
string connectionString = ConfigurationManager.ConnectionStrings["SuoMaWDataConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connectionString);
myConnection.Open();
SqlCommand CmdBig = new SqlCommand(queryBig, myConnection);
SqlDataReader Bigmm = CmdBig.ExecuteReader();
if (Bigmm.Read())
{
Biglbl.Text = Bigmm["CategoryBig_Name"].ToString().Trim();
}
}
希望可以帮助你。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询