for (int i = 0; i < GridView2.Rows.Count; i++)
{
CheckBox cbx = GridView2.Rows[i].Cells[7].FindControl ("CheckBox1") as CheckBox;
if (cbx.Checked) (Image)(GridView1.Rows[i].Cells[7].FindControl("Image1")).Visible = true;
else
(Image)(GridView1.Rows[i].Cells[7].FindControl("Image1")).Visible = false;
这段代码的毛病在哪啊?
{
CheckBox cbx = GridView2.Rows[i].Cells[7].FindControl ("CheckBox1") as CheckBox;
if (cbx.Checked) (Image)(GridView1.Rows[i].Cells[7].FindControl("Image1")).Visible = true;
else
(Image)(GridView1.Rows[i].Cells[7].FindControl("Image1")).Visible = false;
这段代码的毛病在哪啊?
<asp:TemplateField HeaderText="序号">
<ItemTemplate>
<%# Container.DisplayIndex + 1 %>
<asp:Image ID="Image1" runat="server" ImageUrl="../../Images/hurry.gif" Visible='<%# ((DataBinder.Eval(Container.DataItem, "是否紧急").ToString()) != "FALSE") %>'></asp:Image>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"/>
<HeaderStyle Width="30px" />
</asp:TemplateField>
这样写比较好,高效
{
CheckBox cbx = (CheckBox)GridView2.Rows[i].Cells[7].FindControl("CheckBox1");
cbx.Checked=(Image)(GridView1.Rows[i].Cells[7].FindControl("Image1")).Visible;
}
这样应该就可以实现了
但我是想要
CheckBox1是GridView中的一个属性列,
在从数据库中读出时,
在CheckBox1.Checked为真时,
Image1.Visible = true
否则为F
{
CheckBox chkbox = (CheckBox)gvrow.FindControl("chbk");
if(chkbox.Checked)
{
Image img= (Image )gvrow.FindControl("Image1");
img.Visible = false;
}
}
Image image1 = null;
for (int i = 0; i < GridView2.Rows.Count; i++)
{
cbx = GridView2.Rows[i].FindControl("CheckBox1") as CheckBox;
image1 = GridView1.Rows[i].FindControl("Image1") as Image1;
image1.Visible = cbx.Checked;
}