Hi,
I have a gridview to which i am adding rows dynamically at the click event of a button placed in gridview footer template. When i want to update data. I have to load the gridview with all the rows required. I get the sql table data in the dataset object and then i have to load this in the gridview. How can i do this?
Only one row gets loaded when i use this code:
DataSet DSContact = DMLObj.Load_DataSet("Usp_LoadData", "ContactPerson", idf);
foreach (GridViewRow row in GVContactPerson.Rows)
{
((TextBox)row.FindControl("txtContactName")).Text=DSContact.Tables[0].Rows[0]["ContactName"].ToString();
((TextBox)row.FindControl("txtemail")).Text = DSContact.Tables[0].Rows[0]["ContactEmailID"].ToString();
((TextBox)row.FindControl("txtmob1")).Text = DSContact.Tables[0].Rows[0]["ContactMobile"].ToString();
Session["contact"] = ((TextBox)row.FindControl("txtContactName")).Text;
string pid = Convert.ToString(DMLObj.getid("Select ContactPersonID from tbl_ContactPersonDetails where ContactName='" + Session["contact"].ToString() + "'"));
Session["contactID"] = pid;
}
Loading

B M SuchitraPosted Dec 1, 2011, 6:45 AM
My gridview is same as below:
http://www.aspsnippets.com/Articles/Adding-Dynamic-Rows-in-ASP.Net-GridView-Control-with-TextBoxes.aspx
what i need to do is load this gridview with data from the dataset which may have any no of rows. Then update it.. I have problem loading this gridview as i am able to load the gridview with only one row
Mamta MPosted Dec 1, 2011, 6:35 AM
Just saw your response. What error are you getting now? How many rows are present in the DataSet table?
-Mamta
Raghvendr SinghPosted Dec 1, 2011, 6:06 AM
For that task follow the process as bellow.
1.First declare a session table eg. Session["Table1"].
2.declare a datatable 'dt'.
3.Place the session table into datatable 'dt'.
4.add a row in table 'dt' on button click event and at once place the table 'dt' into session table to preserve data.
5.simply bind session table in gridview.
B M SuchitraPosted Dec 1, 2011, 12:52 AM
I tried out with that but still not getting the desired result..
I am adding rows to gridview using this concept:
http://www.aspsnippets.com/Articles/Adding-Dynamic-Rows-in-ASP.Net-GridView-Control-with-TextBoxes.aspx
Mamta MPosted Dec 1, 2011, 12:12 AM
((TextBox)row.FindControl("txtContactName")).Text=DSContact.Tables[0].Rows[0]["ContactName"].ToString();
See the bolded text, that's always 0. That must be incremented for each iteration of the loop. Use an int variable such as i that's incremented and give Rows[i].