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 !
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.
this worked!
I just had to change the item index to match my column index (didn't know that's what items means)
Thanks.
This is actually what I did:
TextBox txtBxURL = WbDtGrdAppVersion.Rows.FromKey(new Object[] { e.CommandArgument }).Items[10].FindControl("txtBxURL") as TextBox;
Instead of iterating through the collection, I accessed it with the row key.
Thank you! This worked for me too!