Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All

I have a grid view and having template field like this

ASP.NET
<asp:TemplateField HeaderText="ISIN Name">
 <itemtemplate>
 <asp:TextBox ID="TextBox2" runat="server" Enabled="false">
 </itemtemplate>
<itemstyle borderstyle="Groove" horizontalalign="left" verticalalign="Middle" cssclass="commontablebg" width="50px" />


whenever i am adding new row like following dynamically on button click text in that textbox disappears

C#
private void AddNewRowToGrid(string param)
{
 int rowIndex = 0;
if (ViewState("CurrentTable") != null)
{
 DataTable dtCurrentTable = (DataTable)ViewState("CurrentTable");
DataRow drCurrentRow = null;
if (dtCurrentTable.Rows.Count > 0)
{
for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
{
 TextBox box1 = (TextBox)grdDematChk.Rows(rowIndex).Cells(1).FindControl("TextBox1"); /TextBox box2 = (TextBox)grdDematChk.Rows(rowIndex).Cells(2).FindControl("TextBox2"); TextBox box3 = (TextBox)grdDematChk.Rows(rowIndex).Cells(3).FindControl("TextBox3"); TextBox box4 = (TextBox)grdDematChk.Rows(rowIndex).Cells(4).FindControl("TextBox4"); TextBox box5 = (TextBox)grdDematChk.Rows(rowIndex).Cells(5).FindControl("TextBox5"); TextBox box6 = (TextBox)grdDematChk.Rows(rowIndex).Cells(6).FindControl("TextBox6"); TextBox box7 = (TextBox)grdDematChk.Rows(rowIndex).Cells(7).FindControl("TextBox7");

drCurrentRow = dtCurrentTable.NewRow(); // dtCurrentTable.Rows.Add(drCurrentRow) //drCurrentRow("RowNumber") = i + 1 dtCurrentTable.Rows[i - 1][0] = box1.Text;
 dtCurrentTable.Rows[i - 1][1] = box2.Text;
dtCurrentTable.Rows[i - 1][2] = box3.Text;
dtCurrentTable.Rows[i - 1][3] = box4.Text;
dtCurrentTable.Rows[i - 1][4] = box5.Text;
 dtCurrentTable.Rows[i - 1][5] = box6.Text;
 dtCurrentTable.Rows[i - 1][6] = box7.Text;
rowIndex += 1;
}
 if ((param != "R"))
 {
dtCurrentTable.Rows.Add(drCurrentRow);
 }
grdDematChk.DataSource = dtCurrentTable; grdDematChk.DataBind();
 }
}
else
{
Response.Write("ViewState is null");
}
 //Set Previous Data on Postbacks SetPreviousData();
 }


private void SetPreviousData()
{
 int rowIndex = 0;
if (ViewState("CurrentTable") != null)
 {
 DataTable dt = (DataTable)ViewState("CurrentTable");
if (dt.Rows.Count > 0)
{
 for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
 TextBox box1 = (TextBox)grdDematChk.Rows(rowIndex).Cells(1).FindControl("TextBox1");  TextBox box2 = (TextBox)grdDematChk.Rows(rowIndex).Cells(2).FindControl("TextBox2"); TextBox box3 = (TextBox)grdDematChk.Rows(rowIndex).Cells(3).FindControl("TextBox3"); TextBox box4 = (TextBox)grdDematChk.Rows(rowIndex).Cells(4).FindControl("TextBox4"); TextBox box5 = (TextBox)grdDematChk.Rows(rowIndex).Cells(5).FindControl("TextBox5"); TextBox box6 = (TextBox)grdDematChk.Rows(rowIndex).Cells(6).FindControl("TextBox6"); TextBox box7 = (TextBox)grdDematChk.Rows(rowIndex).Cells(7).FindControl("TextBox7");

box1.Text = dt.Rows[i][0].ToString(); box2.Text = dt.Rows[i][1].ToString(); box3.Text = dt.Rows[i][2].ToString(); box4.Text = dt.Rows[i][3].ToString(); box5.Text = dt.Rows[i][4].ToString(); box6.Text = dt.Rows[i][5].ToString(); box7.Text = dt.Rows[i][6].ToString();
rowIndex += 1;
}
}
 }
 }
Posted
Updated 15-Sep-11 2:28am
v3
Comments
[no name] 15-Sep-11 8:43am    
What you have written down on button click??
mayur csharp G 15-Sep-11 9:04am    
i have just called this function
private void AddNewRowToGrid(string param)

1 solution

You have not called setpreviousData method in AddNewRowToGrid method
 
Share this answer
 
Comments
mayur csharp G 15-Sep-11 9:29am    
i have called but i think forgot to mention it here

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900