How to add row to gridview at the run time in asp.net? I am using c# as a language. Please help me regarding this.
It depends on what you are trying to acheive. You can either add the row to the datatable/ dataset before binding it to the gridview or add it to the gridview after the data has been bound (if your wanting it to appear on every page if your using paging)
I am making online billing system and I want to add more than one items and I want to use gridview control
You can add any number of data to gridview. First you collect data to a datatable and bind it to gridview
Hi............ The following snippet demonstrates adding of row to grid view programmatically at run-time. just learn it ....it will help you.. Name spaces to used are: using System.Data.SqlClient; using System.Data; Step1: The following code should be coded under page load event SqlConnection cn = new SqlConnection("user id=admin;password=admin123;data source=ganesh1"); SqlDataAdapter da = new SqlDataAdapter("select * from emp", cn); ds = new DataSet(); da.Fill(ds, "temp"); GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); Step2: The following code should be coded under row created event of grid view protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { //checking whether rowtype is datacontrolrowtype if (e.Row.RowType == DataControlRowType.DataRow) { double annsal; //getting the required data from database annsal =double .Parse ( ds.Tables[0].Rows[e.Row.RowIndex]["sal"].ToString()) * 12; //initializing and adding label control to gridview Label l1=new Label(); l1.Text =annsal .ToString (); e.Row .Cells [1].Controls .Add (l1); //checking tha annsal and drawing the row with particular color if (annsal > 1000) { e.Row.BackColor = System.Drawing.Color.Red; } else e.Row.BackColor = System.Drawing.Color.Gray; } } Step 3: Customize the gridview.Use 2 templates Template 1--> A) Header Text -->Employee Name B) Place Label in Item Template and bind Text to Eval("Ename") Template2--> A) Header Text=Annual Salary Set Auto Generate fields to False Step 4: Execute Explanation -->The grid view is binded with the database -->using row created event of grid view add the row to grid view at runtime Web Designer | Real Estate Web Design