ASPNET DataGrid Rebind Issue on Serverside formatting

G

Guest

Here is a snippit which replicates my issue. I have a datagrid which contains
an input textbox on each row, binded on the serverside. However it seems that
when I perform a postback to refresh teh numbers, they are not changing due
to the foreach loop I have in this code. When I comment out the foreach loop,
the numbers refresh fine (but the text boxs ovbiously no longer get created).
I have placed this code in the OnItemDataBind method, which the same problem.
I have set the EnableViewState to false on the grid, other then that the
grid has default attributes.

I basically would like to rebind the data upon postback, while keeping the
content in the input text boxes intact.

private void LoadBlotter(System.Web.UI.WebControls.DataGrid oDataGrid)
{
DataSet oDS = new DataSet();
oDS.ReadXml(new StringReader(@"<NewDataSet>
<Table1>
<ID>Value1</ID><Name> " + System.DateTime.Now.Second.ToString() + @"
</Name><Input></Input></Table1><Table1>
<ID>Valie2</ID><Name> " + System.DateTime.Now.Millisecond.ToString() + @"
</Name><Input></Input></Table1>
</NewDataSet>"));
oDataGrid.DataSource = oDS.Tables[0].DefaultView;
oDataGrid.DataBind();
// Apply some special formatting
foreach(DataGridItem e in oDataGrid.Items)
{
Double dReq = Convert.ToDouble(e.Cells[1].Text);
System.Web.UI.WebControls.TextBox o1ReqTbox = new TextBox();
o1ReqTbox.Attributes.Add("onblur","CalcFunded()");
o1ReqTbox.Text = dReq.ToString("#,##0");
o1ReqTbox.CssClass = "criteriaTableCustom";
o1ReqTbox.ReadOnly = true;
e.Cells[1].Controls.Add(o1ReqTbox);

System.Web.UI.WebControls.TextBox ofundedTbox = new TextBox();
ofundedTbox.Attributes.Add("onblur","CalcFunded()");
ofundedTbox.CssClass = "criteriaTableCustom";
e.Cells[2].Controls.Add(ofundedTbox);
}
}

<asp:datagrid EnableViewState=False id=FSummary Runat="server"
name="FSummary">
</asp:datagrid>

Hope ya'll can help
 

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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top