Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1705
Find control in a templated column
posted

Hey guys, 

 

I read somewhere that templated columns cannot be edited, so I dropped a textbox and a linkbutton right in the templated column in order to update the field:

<ig:TemplateDataField Key="URL" Header-Text="URL" >            

    <ItemTemplate >

        <a runat="server" id="URLLink" href='<%# Eval("URL")%>' >Link</a>

        <br />

        <asp:TextBox runat="server" ID="txtBxURL"></asp:TextBox> <asp:LinkButton runat="server" ID="lnkBttnChangeURL" Text="Update" CommandName="ChangeURL" CommandArgument='<%# Eval("RowID")%>'/>                    

    </ItemTemplate>                                               

</ig:TemplateDataField>

The problem is I can't find a way to get a reference to the TextBox control. I tried the following line of code within the OnItemCommand event (fired by the link button):

((TemplateDataField)this.WbDtGrdAppVersion.Columns["URL"]).ItemTemplate

but ItemTemplate doesn't seem to have a FindControl or some sort of collection of controls.

Any help would be appreciated.

 

Thanks !

 

Parents
  • 40
    Verified Answer
    posted

    In order to reference the TextBox control in a templated column you need to create a TextBox instance in your code behind and use the FindControl in the grid.items.  Below is a code sample.

    TextBox oTextBox = new TextBox();

    foreach (GridRecord oGridRecord in YourGridHere.Rows)
    {
         oTextBox = (TextBox)oGridRecord.Items[0].FindControl("txtBxURL");
    }

    This will give you access to the text box in your grid.

Reply Children