Results 1 to 6 of 6

Thread: how to access template column in code behind

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    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
    There is no achievement without goals

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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:

    i want that if it is checked it should become disable
    Gary

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: how to access template column in code behind

    means checkbox got disabled like checkbox.enable=false
    There is no achievement without goals

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    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
    There is no achievement without goals

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width