首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

怎么操作GridView模板里的控件

2012-01-05 
如何操作GridView模板里的控件如何操作GridView模板里的控件asp:GridViewID GridView1 runat server

如何操作GridView模板里的控件
如何操作GridView模板里的控件
<asp:GridView   ID= "GridView1 "   runat= "server "   CellPadding= "4 "                           <Columns>
                                <asp:BoundField   HeaderText= "用户名 "   DataField= "username "   />
                                <asp:BoundField   HeaderText= "姓别 "   DataField= "sex "   />
                                <asp:BoundField   HeaderText= "留言内容 "   DataField= "body "   />
                                <asp:BoundField   HeaderText= "QQ号码 "   DataField= "qq "   />
                                <asp:BoundField   HeaderText= "E-Mail "   DataField= "email "   />
                                <asp:TemplateField   HeaderText= "是否有效 ">
                                <ItemTemplate>
                                <asp:CheckBox   id= "isValue "   Enabled=false   Checked= <%#   (bool)Eval( "IsHidden ")   %>   runat= "server "> </asp:CheckBox>
                                <asp:Button   id= "Button1 "   runat= "server "   Text= "Button "> </asp:Button>
                                </ItemTemplate>
                                </asp:TemplateField>
                                <asp:CommandField   ButtonType= "Button "   ShowEditButton= "True "   />
                        </Columns>
                </asp:GridView>


刚绑定的时候checkbox是不可编辑的,我想在按了编辑按钮后checkbox可以编辑,请对checkbox进行操作,直接isValue.Enabled=True是肯定的了

[解决办法]
加一个EditItemTemplate
<asp:GridView ID= "GridView1 " runat= "server " CellPadding= "4 " <Columns>
<asp:BoundField HeaderText= "用户名 " DataField= "username " />
<asp:BoundField HeaderText= "姓别 " DataField= "sex " />
<asp:BoundField HeaderText= "留言内容 " DataField= "body " />
<asp:BoundField HeaderText= "QQ号码 " DataField= "qq " />
<asp:BoundField HeaderText= "E-Mail " DataField= "email " />


<asp:TemplateField HeaderText= "是否有效 ">
<ItemTemplate>
<asp:CheckBox id= "isValue1 " Enabled=false Checked= <%# (bool)Eval( "IsHidden ") %> runat= "server "> </asp:CheckBox>
<asp:Button id= "Button1 " runat= "server " Text= "Button "> </asp:Button>
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox id= "isValue2 " Enabled=true Checked= <%# (bool)Eval( "IsHidden ") %> runat= "server "> </asp:CheckBox>
<asp:Button id= "Button2 " runat= "server " Text= "Button "> </asp:Button>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType= "Button " ShowEditButton= "True " />
</Columns>
</asp:GridView>

热点排行