Jump to content

gridview


seema
 Share

Recommended Posts

:) 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

  • 4 weeks later...

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...