Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit/Update in DataGrid - Getting Old Values ????

Status
Not open for further replies.

DilipKS

Programmer
Mar 8, 2004
30
CH
Hi
I am using DataGrid with two columns, one column is read only having label inside and second column having text box inside. ( am using Template column ).
Both columns are bind to data columns ( see the code below ).
But the problem am facing is when am updating values in second column i.e. Text boxes and trying to retrieve it and getting old values .

am trying to use
TextBox txtVal = (TextBox)this.DataGrid1.Items.FindControl("txtValue");
But txtVal.Text is giving me old values ...
Any Idea ?




<asp:TemplateColumn HeaderText="Field">
<ItemStyle BackColor="LightGray"></ItemStyle>
<ItemTemplate><asp:Label id="lblField" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Field") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Value">
<ItemStyle BackColor="LightGray"></ItemStyle>
<ItemTemplate><asp:TextBox id=txtValue runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Value") %>' EnableViewState="False"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
 
in your code behind file, are you rebinding data to the grid every time a button is pressed ?

(This Caught me out recently)

Make sure if you bind data to the datagrid in the initialise code you have (c#)

if (!postback)
{
//this is a guess for the right syntax for databinding
dg.databind();
}

hth

k
 
Hi Kalisto,
I got it worked. It worked after I set EnableViewState to False.
DataBind of Grid is fine .
Thnks for the reply anyway.

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top