How to retrieve textbox values from within Placeholder in Gridview

JoshuaVN54

New Member
i have a grid view i added 5 template fields in 1st template field i added a placeholder and next 4 columns are template fields in which i added 3 texboxes 1 button respectively... and later iam adding the texboxes dynamically to place holder of 1st column.its all working fine.. now i want to save the data when i click the save button of the last column..while doin this iam unable to find the dynamically added textbox control which is inside the place holderI used the following code\[code\] <Columns> <asp:TemplateField HeaderText="STUDENT_ID"> <ItemTemplate> <asp:PlaceHolder ID="ph" runat="server"></asp:PlaceHolder> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="STUDENT_NAME"> <ItemTemplate> <asp:TextBox ID="txtName" runat="server"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="DATE OF JOIN"> <ItemTemplate> <asp:TextBox ID="txtDOJ" runat="server"></asp:TextBox> </ItemTemplate> <FooterTemplate> <asp:Button ID="ftrAdd" Text="Add New Row" runat="server" CommandName="AddNewRow"/> </FooterTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <asp:Button ID="btnSave" Text="Save" runat="server" CommandName="Save_Click" CommandArgument='<%#Container.DataItemIndex %>'/> </ItemTemplate> </asp:TemplateField> </Columns>protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e){ if (e.Row.RowType == DataControlRowType.DataRow) { PlaceHolder ph = (PlaceHolder)e.Row.FindControl("ph"); TextBox tb = new TextBox(); tb.ID = "txtID"; ph.Controls.Add(tb); }}protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e){}protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e){ if (e.CommandName == "AddNewRow") { AddNewRow(); } else if (e.CommandName == "Save_Click") { int rowindex = Int32.Parse(e.CommandArgument.ToString()); PlaceHolder ph = (PlaceHolder)GridView1.Rows[rowindex].FindControl("ph"); TextBox tbID = ph.FindControl("txtID") as TextBox; string text=tbID.Text; }}\[/code\]
 
Back
Top