Hello every one,
I have a gridview with following definition
<asp:GridView ID="timegrid" runat="server" AutoGenerateColumns="false" ShowHeader="true" OnRowDataBound="timegrid_RowDataBound" OnRowCreated="timegrid_RowCreated">
<Columns>
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
<asp:TemplateField>
<ItemTemplate>
<asp:PlaceHolder ID="place1" runat="server"></asp:PlaceHolder>\\5 fields of this type
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and generated row dynamically with textbox and placed it in this place holder as follows:
PlaceHolder pc1 = ((PlaceHolder)e.Row.Cells[4].Controls[1]);
TextBox tb = new TextBox();
tb.ID = "tb_4" ;
tb.Width = 50;
tb.Style.Add("text-align", "center");
pc1.Controls.Add(tb);
Its working fine as expected.
Now i have one button located outside gridview. On click of this button i want to access that controls which were generated dynamically as well as other gridview cells values also,i am not able to access it. I tried like
TextBox textBox = timegrid.Rows[0].Cells[4].FindControl("tab_4") as TextBox;
string temp = textBox.Text;\\Object reference error
Here i have only single row with multiple columns.I am getting error at highlighted line.Does this controls looses on postback(on button click)?If so,how to avoid that?
How to proceed? Any suggestions please..?