473,587 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 EditCommandColu mn 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, DataGridCommand EventArgs e)
{
dgDetails.EditI temIndex = e.Item.ItemInde x;
BindDataGrid();
}

and this is my BindDataGrid() method definition

private void BindDataGrid()
{
//DataTable dt = new DataTable();
connObj = this.OpenConnec tion();
strSql = "Select Remarks from HDSurveyMaster" ;
dsRemarks = SqlHelper.Execu teDataset(conn, CommandType.Tex t,strSql);

strSql = "Select DisplayOrder from HDSurveyMaster" ;
dsOrder = SqlHelper.Execu teDataset(conn, CommandType.Tex t,strSql);
object order=null;

try
{
DataColumn cRemarks = new DataColumn();
cRemarks.Captio n = "Remarks";
cRemarks.Column Name = "Remarks";
dt.Columns.Add( cRemarks);

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

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

for(int j=0; j< dsOrder.Tables[0].Rows.Count; j++)
{
order = dsOrder.Tables[0].Rows[j]["DisplayOrd er"];
}
dr["Order"] = order;
dt.Rows.Add(dr) ;
}
ds.Clear();
ds.Tables.Add(d t);
dgDetails.DataS ource = ds.Tables[0].DefaultView;
dgDetails.DataB ind();
}

catch(AFExcepti on 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 1133

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

Similar topics

2
3624
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 a row. Everything works just fine. BUT I would like to add a button to (for example) the DataGrid header, which when pressed will add a new...
0
1660
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 apear in the DataGrid but still no response from the form. If I add the same data to a rich text box and don't use the datagrid I don't have this...
3
4866
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 the best method? Do you have a sample of how to do this?
1
3268
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 days of struggling, I figure asking you all (the experts) will keep me from going down some dark and dangerous road. The project I have is a fairly...
2
1956
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 DataGridItem(DataGrid1.Items.Count+1,DataGrid1.Items.Count+1,ListItemType.Item); di.Cells.Add(tc); di.Cells.Add(tc1);
2
2427
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 the Columns dialog box from the properties of the datagrid, on the left that contains a select button. So now, when you press the button the whole...
1
1363
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 to a datagrid? would also appriciate if you could give me some nice articles on how to add new rows to a datagrid... thanks.
2
3553
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 DataTable("MyTable"); In the classes constructor, after InitializeComponent() I call the following
12
6196
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 datagrid. Once I can get to that point I need some way to be able to add new data only to the new columns that were added. Here is some of my...
1
3826
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 datagrid.It is displaying the separators properly in the web page. In the save button click, I am looping through the datagrid items and then...
0
7920
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8215
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8347
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7973
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6626
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5394
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.