Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to generate nested grid view from grid view row add button.if i click add button nested grid view have to be generate based on parent grid ID.

For example parent grid id=1 means while clicking add nested grid row have to be generated with auto increment ID while each time clicking add button(like 1.1,1.2) If second row from parent grid means 2.1,2.2 like this have to create in nested grid row id

What I have tried:

while clicking add in grid view row:
using two tables while concatenating 1.1,1.2 for first row.if i add in second row it showing 2.3 how to solve. using data table is easy means how to do it?
C#
protected void OnSelectedIndexChanged(object sender, EventArgs e)
     {

         string Sid = GridState.SelectedRow.Cells[1].Text;
         SqlConnection con = new SqlConnection(conString);
         {
             using (SqlCommand cmd = new SqlCommand("INSERT INTO City  VALUES('" + TextBox3.Text + "' , '" + TextBox4.Text + "' , '" + TextBox5.Text+"' , " + Sid+")", con))
             {

                 con.Open();
                 cmd.ExecuteNonQuery();
                 con.Close();

                 string sQuery1 = "SELECT CAST(S_id AS VARCHAR(20) ) +'.'+ CAST(City_id AS VARCHAR(20) ),City_code,City_name from City where S_id="+Sid;
                 string value=getData1(sQuery1).ToString();
                 //string sQuery = "SELECT CAST(S_id AS VARCHAR(20) ) +'.'+ CAST(City_id AS VARCHAR(20) ),City_code,City_name from City";
                 ////GridView City = e.Equals("GridCity") as GridView;

                 //GridState.DataSource = getData(sQuery);
                 //GridState.DataBind();

             }

         }
Posted
Updated 15-Jun-17 1:32am
v2
Comments

1 solution

No idea what you tried (as you did not tell us), but take a look at asp gridview auto increment column - Google Search[^].
 
Share this answer
 
Comments
GrpSMK 15-Jun-17 7:33am    
Check now pls
Richard MacCutchan 15-Jun-17 8:12am    
Sorry I am not an ASP programmer. All I will say is that your database is wide open to SQL injection, so do not be surprised when you lose all your data.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900