cannot change value of texbox w/in datagrid after first bind

  • Thread starter Thread starter Michael via .NET 247
  • Start date Start date
M

Michael via .NET 247

I have a datagrid with the columns defined in the aspx
<columns>
<asp:TemplateColumn HeaderText="Hours" ItemStyle-Width="1%"ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:TextBox Columns="2" EnableViewState="False" ID="Hours"Runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
...
</columns>

I have other bound columns that display the correct data so Iknow the dataset is ok.
Here's the problem. In
dgTest_ItemBound(...) Handles dgTest.ItemDataBound
I have:
CType(e.Item.Cells(3).FindControl("Hours"), TextBox).Text =drv("TotalHours").ToString

When I make the first request, the hours txtbox is populatedcorrectly. Any rebinding after that, the value is unchanged. Ifthe box initially was filled with '20' and the grid was reboundto contain 0 hours, 20 remains, even though another bound columncontaining 'TotalHours' DOES change. This is very strange. Anyideas?

I've already tried things with viewstate on/off for the dg andtxtbox. I've already tried adding the textbox controldynamically and clearing it, etc. No good.

I also tried using <asp:textbox><%# eval....container...%></asp:textbox> but you can't do that for other reasons.

Any help if appreciated. Thank you.
 
Hi,

Sounds like you are filling the dataset even when you are posting back.

Ken

--------------------------


I have a datagrid with the columns defined in the aspx
<columns>
<asp:TemplateColumn HeaderText="Hours" ItemStyle-Width="1%"
ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:TextBox Columns="2" EnableViewState="False" ID="Hours"
Runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
...
</columns>

I have other bound columns that display the correct data so I know the
dataset is ok.
Here's the problem. In
dgTest_ItemBound(...) Handles dgTest.ItemDataBound
I have:
CType(e.Item.Cells(3).FindControl("Hours"), TextBox).Text =
drv("TotalHours").ToString

When I make the first request, the hours txtbox is populated correctly. Any
rebinding after that, the value is unchanged. If the box initially was
filled with '20' and the grid was rebound to contain 0 hours, 20 remains,
even though another bound column containing 'TotalHours' DOES change. This
is very strange. Any ideas?

I've already tried things with viewstate on/off for the dg and txtbox. I've
already tried adding the textbox control dynamically and clearing it, etc.
No good.

I also tried using <asp:textbox><%# eval....container... %></asp:textbox>
but you can't do that for other reasons.

Any help if appreciated. Thank you.
 

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

Back
Top