473,395 Members | 1,502 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,395 software developers and data experts.

editing in datagrid

hello guys thanks for the previous reply
now my problem is that i want to display the data in the datagrid from database also i want to edit the data in the datagrid but it is also not providing an update and cancel button if anybody could help me out i am posting my code below

Expand|Select|Wrap|Line Numbers
  1. private void Page_Load(object sender, System.EventArgs e)
  2.         {
  3.             if (!Page.IsPostBack)
  4.             {
  5.                 BindData();
  6.             }
  7.  
  8.  
  9.             // Put user code to initialize the page here
  10.             OleDbDataAdapter da = new OleDbDataAdapter("SELECT *FROM CMRS_BUSINESSAREA_MASTER","Provider=MSDAORA.1;User ID=meter_reading;Password=colony;Data Source=windev;OLEDB.NET=true;" );
  11.             DataSet ds = new DataSet();
  12.             da.Fill(ds);
  13.             DataGrid1.DataSource = ds.Tables[0].DefaultView ;
  14.             DataGrid1.DataBind();
  15.  
  16. }
  17.     public void BindData()
  18.         {
  19.             OleDbDataAdapter da = new OleDbDataAdapter("SELECT *FROM CMRS_BUSINESSAREA_MASTER","Provider=MSDAORA.1;User ID=meter_reading;Password=colony;Data Source=windev;OLEDB.NET=true;" ); 
  20.             DataSet ds = new DataSet(); 
  21.             da.Fill(ds);
  22.  
  23.             DataGrid1.DataSource = ds.Tables[0].DefaultView ;
  24.             DataGrid1.DataBind();
  25.  
  26.  
  27.         }
  28.         private void Edit_DataGrid1(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) 
  29.         { 
  30.             // We use CommandEventArgs e to get the row which is being clicked 
  31.             // This also changes the DataGrid labels into Textboxes so user can edit them 
  32.             DataGrid1.EditItemIndex = e.Item.ItemIndex; 
  33.             // Always bind the data so the datagrid can be displayed. 
  34.             BindData(); 
  35.         } 
  36.         private void Cancel_DataGrid1(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) 
  37.         { 
  38.             // All we do in the cancel method is to assign '-1' to the datagrid editItemIndex 
  39.             // Once the edititemindex is set to '-1' the datagrid returns back to its original condition 
  40.             DataGrid1.EditItemIndex = -1; 
  41.             BindData(); 
  42.         } 
  43.         private void Update_DataGrid1(object Source, DataGridCommandEventArgs E)
  44.         {
  45.  
  46.  
  47.             OleDbCommand cmd;
  48.  
  49.             TextBox txtAREADESCRIPTION =(TextBox) E.Item.Cells[1].Controls[0];
  50.             string strUpdateStmt;
  51.  
  52.             strUpdateStmt = "UPDATE CMRS_BUSINESSAREA_MASTER SET  " + "AREADESCRIPTION = '" + txtAREADESCRIPTION.Text + "' " + "WHERE AREACODE = " + E.Item.Cells[0].Text;
  53.  
  54.             OleDbConnection con1 = new OleDbConnection("Provider=MSDAORA.1;User ID=meter_reading;Password=colony;Data Source=windev;OLEDB.NET=true;");
  55.             cmd = new OleDbCommand(strUpdateStmt, con1);
  56.             con1.Open();
  57.             cmd.ExecuteNonQuery();
  58.  
  59.             DataGrid1.EditItemIndex = -1;
  60.             BindData();
  61.         }
  62. private void addbtn_Click(object sender, System.EventArgs e)
  63.         {
  64.             string str = ConfigurationSettings.AppSettings["ConnectionString"].ToString();  
  65.  
  66.             OleDbConnection con1 = new OleDbConnection();
  67.             con1.ConnectionString = str;
  68.             OleDbCommand cmd = new OleDbCommand("Insert into cmrs_businessarea_master values('"+TextBox1.Text+"','"+TextBox2.Text+"')",con1);         
  69.             con1.Open();
  70.             cmd.ExecuteNonQuery();
  71.             con1.Close();
  72.  
  73.  
  74.  
  75.         }
  76.  
  77.  
  78.         private void updtbtn_Click(object sender, System.EventArgs e)
  79.         {
  80.             // binddata();
  81.  
  82.         }
  83.  
  84.         private void delbtn_Click(object sender, System.EventArgs e)
  85.         {
  86.  
  87.         }
  88.  
  89.  
  90.  
  91.     }
  92.  
  93.  
  94.  
  95. }
Jul 19 '07 #1
0 908

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

Similar topics

0
by: Swaroop | last post by:
Hi, I am using a Datagrid to populate the details given by a user in the footer of the datagrid.i am using an object array to populate the datagrid(a sample project so not using a database to...
4
by: TT (Tom Tempelaere) | last post by:
Hi, Suppose there is a DataGrid on a form bound to a DataTable. When a user is editing a cell without leaving the cell, and then closes the form, the value is not updated to the underlying data...
3
by: Islamegy | last post by:
When i press btn_save all changed rows in my grid get saved except the last editing row... I want my btn_Save to end editing in the datagrid.. so if user didn't press "enter" after editing last...
1
by: Blake Versiga | last post by:
When editing a datagrid (C#) I need to know if the user changed the value of cell AND what the previous value was. Is this possible? If so how do I get the previous value or at least if the...
0
by: Raterus | last post by:
Here is my only problem with using the datagrid to edit data. Say I have a moderate sized table, with about 15 columns. I want to allow a user to be able to edit most all of these fields, except...
9
by: tshad | last post by:
Is there a way to use your own image in place of the automatic one that ASP uses when doing editing in your DataGrid pages? We already have a style of button we are using and would like to be...
1
by: MrMike | last post by:
I have a sub named Bind("") which binds my a datagrid on my webform. In order to enter edit mode and edit records on this datagrid, I must make a call to Bind("") either before or after I place...
5
by: Sharon | last post by:
I have a DataGrid on my Form, and I wish to disable any cell editing. For example; when the user clicks on a cell, the cell become editable by changing its color to gray and context menu is shown...
0
by: hanusoft | last post by:
This is an example of editing in DataGrid and Default Paging http://www.hanusoftware.com Html Design Code : - <asp:DataGrid id="DataGrid1" DataKeyField="id" runat="server" Height="224px"...
0
by: prerak_v_shah | last post by:
Hi, Friends, I have been developing datagrid program in .Net 1.1 and having VB.Net as a programming language. I have created a datagrid which is bound to a datatable as its datasource. It also...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.