473,224 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 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 1112

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Clayton Hamilton | last post by:
I have a DataGrid on a webform bound to a Datasource and can successfully use <ItemTemplate> to create edit/update/cancel functionality for user maintenance of data. I use separate logic to delete...
0
by: mgenti | last post by:
I am experiencing a problem when I add a row to a DataTable that is used on a DataGrid in my Windows Form application. When I add a new row I no longer get a response from my form. I see the row...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
2
by: Praveen Balanagendra via .NET 247 | last post by:
here is the source code private void AddRow() { TableCell tc = new TableCell(); tc.Controls.Add(new LiteralControl("NewRow")); DataGridItem di = new...
2
by: Bob Hollness | last post by:
Hi group. I am a newbie to ASP.NET as you will see from some of the questions I may ask! I have a datagrid which I have populated from a database. It works great! I have added a column, via...
1
by: Asha | last post by:
grettings, i have been searching the web for articles on how to add new rows to datagrid... most of it does postback. do anyone here know of a good article which uses javascript to add new rows...
2
by: Flack | last post by:
Hey guys, I have a DataGrid and DataTable field in my class : private ImageDataGrid dataGrid1; //ImageDataGrid extends dataGrid and just overides OnMouseDown private DataTable dt = new...
12
by: JMO | last post by:
I can import a csv file with no problem. I can also add columns to the datagrid upon import. I want to be able to start importing at the 3rd row. This will pick up the headers necessary for the...
1
by: AriJayaraman | last post by:
I am having one datagrid in my page where the user will enter some information and that information is saved into database.I am adding separators to my datagrid rows in the pre render event of the...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.