Hi,
how to dynamically create bound fields in gridview and how to update and add new row to such gridview...
Plzz help
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Suthish NairPosted Aug 25, 2011, 12:22 PM
B M SuchitraPosted Aug 25, 2011, 5:40 AM
As i told u earlier i am adding bound fields dynamically
onpageindexchanging="GVDetails_PageIndexChanging"
onrowcancelingedit="GVDetails_RowCancelingEdit"
onrowdeleting="GVDetails_RowDeleting" onrowediting="GVDetails_RowEditing"
onrowupdating="GVDetails_RowUpdating" Font-Names="Tahoma"
Font-Size="8.25pt">
<%--
Vijay YadavPosted Aug 25, 2011, 5:29 AM
B M SuchitraPosted Aug 24, 2011, 6:27 AM
I have checked...I want to know 1 thing.
dtrow["Name"] = ((TextBox)grv.FindControl("txtName")).Text;
from where did u get txtname?
Vijay YadavPosted Aug 24, 2011, 6:18 AM
Have you checked that?
B M SuchitraPosted Aug 24, 2011, 4:02 AM
The code u have given is for gridview which has not been created dynamically... I have created the bound fields dynamically.. In that case how will u add a blank row to the gridview?
Vijay YadavPosted Aug 24, 2011, 3:15 AM
For example:
public void AddNewRow()
{
DataTable dt = new DataTable();
dt.Columns.Add("SrNo", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("City", typeof(string));
foreach (GridViewRow grv in GridView1.Rows)
{
DataRow dtrow;
dtrow = dt.NewRow();
dtrow["SrNo"] = ((Label)grv.FindControl("lblSrNo")).Text;
dtrow["Name"] = ((TextBox)grv.FindControl("txtName")).Text;
dtrow["City"] = ((TextBox)grv.FindControl("txtCity")).Text;
dt.Rows.Add(dtrow);
}
DataRow dtrow1;
dtrow1 = dt.NewRow();
dt.Rows.Add(dtrow1);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void btnAddNewRow_Click(object sender, EventArgs e)
{
AddNewRow();
}
B M SuchitraPosted Aug 24, 2011, 2:59 AM
I have created dynamic bound fields and also have done with the updating .... Can someone tell me how can we add rows to such gridview
Vijay YadavPosted Aug 24, 2011, 1:54 AM
http://www.codeproject.com/KB/aspnet/How_to_create_custom_boun.aspx