Setting the value of a template textbox control in a datagrid

T

Tim_k

The code below finds the user entered value in a textbox within a grid. Then it updates the value(s) to the bound datatable. But the value does not display after rebinding to the grid. I think it has something to do with the binding of the textbox? I'm not clear on whether I have to use DATABINDER.EVAL on each template or not.
Any suggestions?
Thanks,
Tim

For Each dgitem In dgQuery.Items
txt1 = CType(dgitem.FindControl("txtValues"), TextBox) 'Values textbox
Session("dtTable1").Rows(dgitem.ItemIndex).Item("txtValues") = txt1
Next

drTemp = Session("dtTable1").Rows(rowNum)
Session("dtTable1").Rows.Remove(drTemp)

Here's the html for the template textbox in my datagrid:

<asp:TemplateColumn HeaderText="Values">
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:TextBox id="txtValues" runat="server" Width="217px" AutoPostBack="False" ToolTip="Enter Search Value(s)">
</asp:TextBox>
 
T

Tim_k

I found the answer. Use databinder.eval to bind to the dataitem in my datatable as below.
asp:TemplateColumn HeaderText="Values">
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:TextBox id="txtValues" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"txtValues")%>' Width="217px" AutoPostBack="False" ToolTip="Enter Search Value(s)"></asp:TextBox>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top