seema Posted March 23, 2011 Share Posted March 23, 2011 plz help me.....how to add rows dynamically in gridview on a button click.......this is my code...plz correct it for adding multiple rows in gridview without overwriting the previous records....the problm that rite now i m facing is that when i add 2nd row then it overwrites the previous rowprotected void Button1_Click(object sender, EventArgs e){SqlConnection con = new SqlConnection("Data Source=CMA-PC; Initial Catalog= master; Integrated Security=True");SqlDataAdapter da = new SqlDataAdapter("select * from aa1 where Journal_Name='" + DropDownList1.Text + "' AND Issue_No='" + TextBox6.Text + "'", con);DataSet ds = new DataSet();da.Fill(ds);DataTable dt = ds.Tables[0];DataRow dr;dr = dt.NewRow();ds.Tables[0].Rows.Add(dr);GridView1.DataSource = ds;GridView1.DataBind();} Link to comment Share on other sites More sharing options...
sukhdev_ce Posted April 18, 2011 Share Posted April 18, 2011 protected void Button1_Click(object sender, EventArgs e){SqlConnection con = new SqlConnection("Data Source=CMA-PC; Initial Catalog= master; Integrated Security=True");SqlDataAdapter da = new SqlDataAdapter("select * from aa1 where Journal_Name='" + DropDownList1.Text + "' AND Issue_No='" + TextBox6.Text + "'", con);DataSet ds = new DataSet();da.Fill(ds);if(ds.tables[0].Rows.count>0){GridView1.DataSource = ds;GridView1.DataBind();}else{GridView1.EmptyRowText="No Record found.";GridView1.DataSource=null;GridView1.DataBind();}it display all rows by conatining a table define in the Query with matching Conditions define by you. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.