如何在GridView中设置Checkbox值? [英] How to Set the Checkbox value inside GridView?
本文介绍了如何在GridView中设置Checkbox值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何设置位于Gridview内部的CheckBox值?
How to set the CheckBox value, which is located inside a Gridview ?
<asp:GridView ID="gviewPermission" runat="server"
onrowdatabound="gviewPermission_RowDataBound"
onrowupdated="gviewPermission_RowUpdated"
onrowupdating="gviewPermission_RowUpdating">
<Columns>
<asp:TemplateField HeaderText="Allow" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="Check_Allow" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Deny" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="Check_Deny" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
必须根据某些条件设置复选框值...。
The check box value has to set based upon some condition....
推荐答案
在 gviewPermission_RowDataBound
函数中,执行以下操作:
In the gviewPermission_RowDataBound
function do:
if(e.Row.RowType == DataControlRowType.DataRow)
((CheckBox)e.Row.FindControl("Check_Allow")).Checked = SomeCondition;
或者如果条件直接来自数据源,则可以执行以下操作:
Or if the condition is coming directly from the datasource you can do:
<ItemTemplate>
<asp:CheckBox ID="Check_Allow" runat="server"
Checked='<%# Eval("ConditionFromDs") %>' />
</ItemTemplate>
这篇关于如何在GridView中设置Checkbox值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文