在GridView中的检查项目不显示 [英] Checked items in gridview is not displayed
本文介绍了在GridView中的检查项目不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的编码中,我使用带有复选框和列表框的gridview来获取选中的项目.但是选中的项目不会显示在istbox中.
我正在使用以下代码:
In my coding I''m using a gridview with check box and a list box to get the checked items. But the checked items are not displayed in istbox.
I''m using the following code:
protected void btSelect_Click(object sender, EventArgs e)
{
StringCollection sc = new StringCollection();
string id = string.Empty;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox cb = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
if (cb != null)
{
if (cb.Checked)
{
id = GridView1.Rows[i].Cells[1].Text;
sc.Add(id);
}
}
}
foreach (string item in sc)
{
productList.Items.Add(item);
}
}
我是否想念什么?
谢谢.
Whether I''m missing something?
Thankyou.
推荐答案
也许这会帮助 DataGridDemo [ ^ ]
尝试:
Try:
protected void btSelect_Click(object sender, EventArgs e)
{
List<string> sc = new List<string>();
string id = string.Empty;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox cb = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
if (cb != null)
{
if (cb.Checked)
{
id = GridView1.Rows[i].Cells[1].Text;
sc.Add(id);
}
}
}
productList.DataSource = sc.ToArray();
productList.DataBind();
}
引用该线程
http://stackoverflow.com/questions/540304/how-to-get-values-of-checkboxes-inside-gridview-that-are-checked-using-asp-net [ http://www.dreamincode.net/forums/topic/27943-checkbox-in-gridview / [^ ]
Refer this thread
http://stackoverflow.com/questions/540304/how-to-get-values-of-checkboxes-inside-gridview-that-are-checked-using-asp-net[^]
http://www.dreamincode.net/forums/topic/27943-checkbox-in-gridview/[^]
这篇关于在GridView中的检查项目不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文