本文介绍了我需要帮助....这里需要计数,但未绑定到已检查的行中,其绑定始终是第一行...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
int i;
protected void Bindddl_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
System.Web.UI.WebControls.CheckBox chkRow = (row.Cells[i].FindControl("chkRow") as CheckBox);
if (GridView1.Rows.Count > 0)
{
for (i = 0; i < GridView1.Rows.Count; i++)
{
if (chkRow.Checked)
{
TextBox txtjob1 = (TextBox)GridView1.Rows[i].FindControl("txtjob1");
txtjob1.Text = DDLSelJob.SelectedItem.Text;
}
else
{
//TextBox txtjob1 = (TextBox)GridView1.Rows[i].FindControl("txtjob1");
//txtjob1.Text = "";
}
}
}
}
}
推荐答案
protected void Bindddl_Click(object sender, EventArgs e)
{
int i = 0;
foreach (GridViewRow row in GridView1.Rows)
{
System.Web.UI.WebControls.CheckBox chkRow = (row.Cells[i].FindControl("chkRow") as CheckBox);
if (GridView1.Rows.Count > 0)
{
for (i = 0; i < GridView1.Rows.Count; i++)
{
if (chkRow.Checked)
{
TextBox txtjob1 = (TextBox)GridView1.Rows[i].FindControl("txtjob1");
txtjob1.Text = DDLSelJob.SelectedItem.Text;
}
else
{
//TextBox txtjob1 = (TextBox)GridView1.Rows[i].FindControl("txtjob1");
//txtjob1.Text = "";
}
}
}
i++; // your first forloog is not incrementing the i value and by default your i value is 0 u need to increment the i value at the end of your foreach loop.
}
}
这篇关于我需要帮助....这里需要计数,但未绑定到已检查的行中,其绑定始终是第一行...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!