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