Dear All
I have a grid view and having template field like this
<asp:TemplateField HeaderText="ISIN Name">
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Enabled="false"> </asp:TextBox>
</ItemTemplate>
<ItemStyle BorderStyle="Groove" HorizontalAlign="left" VerticalAlign="Middle" cssclass="commontablebg" Width="50px"/>
</asp:TemplateField>
whenever i am adding new row like following dynamically on button click text in that textbox disappears
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;
}
}
}
}