Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you disable bound checkboxes within a datagrid?

Status
Not open for further replies.

j9

Programmer
Jun 6, 2001
90
0
0
US
I added template columns to my datagrid in html view and want to disable the bound checkboxes (I still want them to be visible). I looked at the controls collection but can't seem to figure this out.

<asp:datagrid id="dgGroupMembers" runat="server" AutoGenerateColumns="False" OnItemCommand="dgGroupMembers_Command">

<Columns>
<asp:BoundColumn DataField="FullName" ReadOnly="True" HeaderText="Name"></asp:BoundColumn>

<!-- Checkboxes bound to datasource-->
<asp:TemplateColumn ItemStyle-HorizontalAlign="Center" HeaderText="Reviewer">
<ItemTemplate>
<asp:Checkbox Checked='<%# DataBinder.Eval(Container.DataItem, "IsReviewer") %>' runat="server" ID="chkIsReviewer" />
</ItemTemplate>
</asp:TemplateColumn>


<asp:ButtonColumn Text="update" CommandName="Update"></asp:ButtonColumn>
</Columns>

</asp:datagrid>
 
Do you want to make it disabled at design time?

If so add Enabled="False" to <asp:checkbox declaration.
 
No, during runtime (depending on the type of user). I want all checkboxes within the grid to be disabled. Thanks.
 
FYI, here's the final solution. I had to check for itemindex != -1 because the header row
threw an argument out of range exception.

IN CODE BEHIND PAGE:
public void dgGroupMembers_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if(e.Item.ItemIndex != -1)
{
CheckBox chkReviewer=(CheckBox) e.Item.Cells[1].Controls[1];

if (chkReviewer !=null)
{
chkReviewer.Enabled = false;
}

}
}
-----------------------------
In HTML VIEW:
<asp:datagrid id="dgGroupMembers" runat="server" AutoGenerateColumns="False" OnItemDataBound="dgGroupMembers_ItemDataBound">
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top