473,324 Members | 2,541 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,324 software developers and data experts.

Insert a row in gridview

375 256MB
Hi
I want to insert a row in gridview using C#
I do not want to connect using sqldatasource and input parameters( usually many of them code in UI part). But i DO NOT want that.
i am supposed to do it dynamically. I have to put all code in C#. No connection should be made to SQLDATASOURCE

Thanks
Aug 7 '07 #1
4 1764
cmrhema
375 256MB
Hi
I want to insert a row in gridview using C#
I do not want to connect using sqldatasource and input parameters( usually many of them code in UI part). But i DO NOT want that.
i am supposed to do it dynamically. I have to put all code in C#. No connection should be made to SQLDATASOURCE

Thanks
any one please reply?
Aug 8 '07 #2
radcaesar
759 Expert 512MB
OK, the Make a Connection, Adapter, Command and Dataset.

Bind that dataset to GridView.

Inserting row in Gridview ? I Didn't get that.

In runtime u can add a row using Gridview.Rows.Add() Method.
Aug 8 '07 #3
According to C# vchange the syntax
try this
Dim drRefData As DataRow
drRefData = dtDataTableOfReferecnes.NewRow
drRefData(0) = Me.txtName.Text.Trim
drRefData(1) = Me.txtAddress.Text.Trim
drRefData(2) = Me.txtPhoneNumber.Text.Trim
drRefData(3) = ""
drRefData(4) = 1
dtDataTableOfReferecnes.Rows.Add(drRefData)
Me.dgVLEReferencesInfo.DataSource = dtDataTableOfReferecnes
Me.dgVLEReferencesInfo.DataBind()
Aug 9 '07 #4
cmrhema
375 256MB
I thank all the members who replied

Works now

producing the code below

Thank you once again


Expand|Select|Wrap|Line Numbers
  1. protected void Insert_Click(object sender, EventArgs e)
  2. //This is a link button kept on the footer of the grid. I kept on the Edit footer part
  3. //There are 6 textboxes kept on footer of each field and named accordingly
  4. {
  5.  
  6.  
  7. string id1 = (GridView2.FooterRow.FindControl("txtID") as TextBox).Text;
  8.  
  9. string name1 = (GridView2.FooterRow.FindControl("txtNAME") as TextBox).Text;
  10.  
  11. string date1 = (GridView2.FooterRow.FindControl("txtDATE") as TextBox).Text;
  12.  
  13. string qty1 = (GridView2.FooterRow.FindControl("txtQTY") as TextBox).Text;
  14.  
  15. string price1 = (GridView2.FooterRow.FindControl("txtPRICE") as TextBox).Text;
  16.  
  17. string amt1 = (GridView2.FooterRow.FindControl("txtAMT") as TextBox).Text;
  18.  
  19. SqlConnection cnn = new SqlConnection("Server=HEMALATHA\\SQLEXPRESS;Integrated Security=SSPI;database=demo");
  20.  
  21. cnn.Open();
  22.  
  23. string sqlCommand = "insert into t1 values(" + id1 + ",'" + name1 + "','" + date1 + "'," + qty1 + "," + price1 + "," + amt1+")";
  24.  
  25. SqlCommand cmd = new SqlCommand(sqlCommand,cnn);
  26.  
  27. cmd.ExecuteNonQuery();
  28.  
  29. GridView2.DataBind();
  30.  
  31. Display();
  32. //The above is a method which will display the entire grid
  33. }
Now only one more help, I want to place a dtpicker instead of textbox for inserting date values. I tried the calendar control. But that increased the breadth and width of the gridview.

Any suggestions please.

Thanks
Aug 10 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: scartin | last post by:
I'm fairly new to working with ASP web controls, and am running into what seems to be a ridiculous problem that I'm hoping will be a breeze for an experienced ASP developer. I have a GridView...
1
by: JayD | last post by:
Here is the problem: Using asp.net 2.0 to create a web app with standard master table gridview and child detailsview with insert capability. SQL Server 2000 database on the backend. Using Visual...
3
by: jobs | last post by:
I know native gridview does not support this and/insert of new rows.. what's killing me is I use to have this code that worked around this but somehow I lost it. I recall suffering through it. ...
1
by: =?Utf-8?B?SGFycnkgS2Vjaw==?= | last post by:
I have a GridView that I dynamically add columns to in code. The way that my code is written, everything works properly if I use GridView.Columns.Add to simply add the columns to the end of the...
1
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some...
1
by: Anilsg | last post by:
Hi all, I have the DropDownList in the FormView,inside InsertTemplateField The data is binded in run time to it in codebehind page,FOr the First time the page is loaded the DropdownList is...
0
by: Anilsg | last post by:
Hi all, I have the DropDownList in the FormView,inside InsertTemplateField The data is binded in run time to it in codebehind page,FOr the First time the page is loaded the DropdownList...
2
by: shapper | last post by:
Hello, I am working with a ListView but I suppose that with a GridView might be the same. Instead of having an Insert Button on each GridView row I would like to have only one Insert button,...
0
by: troydixon | last post by:
Hello, I am new at this, and have been trying to insert data into a table by using the footer of a gridview (which I dont like) or by using a detials view on the same page that is doing the...
0
BeemerBiker
by: BeemerBiker | last post by:
I was wondering if a command like "SqlDataSource1.insert()" can somehow give me the new index that was created when the insert took place. If the insert always occurs at the end of the dataset then...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.