473,397 Members | 2,056 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,397 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 1122

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.