narasiman rao

narasiman rao

  • NA
  • 519
  • 743.5k

Adding value to datatable and bind to gridview

Sep 10 2015 2:29 AM
   In run mode as follows

Major code AMC(Dropdownlist) Minor code AFF(dropdownlist) Button(Add)
BMC

Add button code as follows
protected void btnadd_Click(object sender, EventArgs e)
{
Dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Major Code", typeof(string)),
new DataColumn("Minor Code", typeof(string))});
Dt.Rows.Add(ddlmjrcode.SelectedItem.ToString(), ddlminorcode.SelectedItem.ToString());

gvmajormaster.DataSource = Dt;
gvmajormaster.DataBind();
}

When i click the add button i want to add the AMC and AFF in first row in gridview and second row AMC and BMC for that how can i do in asp.net using c#.

Excepted output in Gridview as follows
Major code     Minor code
AMC                          AFF
AMC                           BMC

But my output in gridview as follows
Major code     Minor code
AMC                 AFF

When i add the second minor code in gridview in first row Minor code gets replaced.

for that how can i do in asp.net using c#.
 

Answers (3)