how to access template column in code behind
i have following code to bind gridview with sql datasource
Code:
<asp:GridView AllowPaging=True ID="GridView1" runat="server"
DataSourceID=SqlDataSource1 DataKeyNames=userid
AutoGenerateColumns="False" BackColor="White"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3"
Width="449px" style="margin-right: 0px" PageSize="40">
there is template column in grid
Code:
<asp:TemplateField HeaderText="Approve">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" Enabled=true runat="server" Checked='<%# Bind("Approve") %>' />
</ItemTemplate>
</asp:TemplateField>
if it is 0 it checked it(checkbox) otherwise not ,all are enable too
, i want that if it is checked it should become disable ,secondly i write some lines in code behind like row_databound event and put certain break point but it does not stop over that break point
any help
Re: how to access template column in code behind
Hello,
The checking and unchecking of the CheckBox will not have any impact of the RowDataBound event. The RowDataBound event occurs when the DataSource first binds.
Can you clarify what you mean by:
Quote:
i want that if it is checked it should become disable
Gary
Re: how to access template column in code behind
means checkbox got disabled like checkbox.enable=false
Re: how to access template column in code behind
Hey,
Ok, that is what I thought, but this didn't make much sense to me. Are you saying that once the user clicks the CheckBox, that they shouldn't be able to uncheck it?
Gary
Re: how to access template column in code behind
well for example
Code:
<asp:TemplateField HeaderText="Want Visa">
<ItemTemplate>
<asp:CheckBox ID="chkvisa" Enabled=false runat="server" Checked='<%# Bind("want_visa") %>' />
</ItemTemplate>
</asp:TemplateField>
This disabled all rows ,but i want rows to be disabled that are just checked .
Thanks
Re: how to access template column in code behind
In which case, you would need to bind the Enabled property, in the same way that you are the Checked property.
i.e. if the CheckBox is checked, you want the Enabled Property to be false.
Based on what you have now told us, I would say that the RowDataBound event is the correct place to do this. In the RowDataBound event, find the CheckBox using FindControl, then, depending on the value of "want_visa", set the Checked and Enabled properties accordingly.
Gary