471,356 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,356 software developers and data experts.

Adding rows to a datagrid

Hi
I am doing a web application in which I have a datagrid with 3 columns. I am
populating the 1st column(label) and the 3rd column(dropdown list) from the
database. Before the 1st column I added an EditCommandColumn which displays
the Edit button for me. But when I click the Edit button for a particular
row, it sure displays a textbox for editing but I can't see the previous text
anymore. The same with the 3rd column's dropdown,,it shows an empty dropdown
list. I am calling the method for re-binding the grid as

protected void dgDetails_Edit(object sender, DataGridCommandEventArgs e)
{
dgDetails.EditItemIndex = e.Item.ItemIndex;
BindDataGrid();
}

and this is my BindDataGrid() method definition

private void BindDataGrid()
{
//DataTable dt = new DataTable();
connObj = this.OpenConnection();
strSql = "Select Remarks from HDSurveyMaster";
dsRemarks = SqlHelper.ExecuteDataset(conn,CommandType.Text,str Sql);

strSql = "Select DisplayOrder from HDSurveyMaster";
dsOrder = SqlHelper.ExecuteDataset(conn,CommandType.Text,str Sql);
object order=null;

try
{
DataColumn cRemarks = new DataColumn();
cRemarks.Caption = "Remarks";
cRemarks.ColumnName = "Remarks";
dt.Columns.Add(cRemarks);

DataColumn cOrder = new DataColumn();
cOrder.Caption = "Order";
cOrder.ColumnName = "Order";
dt.Columns.Add(cOrder);

for (int i=0;i<dsRemarks.Tables[0].Rows.Count;i++)
{
DataRow dr;
dr = dt.NewRow();
dr["Remarks"] = dsRemarks.Tables[0].Rows[i]["Remarks"];

for(int j=0; j< dsOrder.Tables[0].Rows.Count; j++)
{
order = dsOrder.Tables[0].Rows[j]["DisplayOrder"];
}
dr["Order"] = order;
dt.Rows.Add(dr);
}
ds.Clear();
ds.Tables.Add(dt);
dgDetails.DataSource = ds.Tables[0].DefaultView;
dgDetails.DataBind();
}

catch(AFException af)
{
throw af;
}
return;
}
Am not sure where am going wrong.

That aside, I also need to write the code if the user wants to add a new
row. How do I do that?

Can anyone help me with it?

Thanks
Jul 21 '05 #1
0 1056

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Clayton Hamilton | last post: by
reply views Thread by mgenti | last post: by
3 posts views Thread by Jim Heavey | last post: by
2 posts views Thread by Bob Hollness | last post: by
1 post views Thread by Asha | last post: by
2 posts views Thread by Flack | last post: by
1 post views Thread by AriJayaraman | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.