468,765 Members | 1,738 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

how to update data in datagrid by an update button outside the datagrid

Dear all,
actually i spent a whole month on the R&D of datagrid edit ,update,cancel events but recently my guide told me to make it user friendly because no user would like to go on searching rows and columns in a datagrid if there are number of rows and columns.so in my web page i have got two labels two textboxes and three buttons namely add update and delete so when i click on the add button the data is added to datagrid and also displayed .....now i need the datagrid to function in such a manner that when i select a row it is selected in the datagrid(which has got only two columns of which one doesnt need to be updated as it being the primary key) and the data is automatically displayed in the textboxes and i can update it there and then when i click the update button it is updated in the datagrid........anybody please provide the code being a beginner i cant figure it out how to do it.....also if someone can provide the code to put a checkbox to select a particular row in datagrid and a search button to search anything in the datagrid it will be whole lot of help .........

i am pasting the present code
here my table name is CMRS_BUSINESSAREA_MASTER the column names are CBM_BUSAREA_CODE(which doesnt need to be updated) and CBM_BUSAREA_DESC
the datatype i am using is varchar2
the .net framework is 1.1 and visual studio.net 2003
Expand|Select|Wrap|Line Numbers
  1. private void Page_Load(object sender, System.EventArgs e)
  2.         {
  3.  
  4.             if (!Page.IsPostBack)
  5.             {
  6.                 BindData();
  7.             }        
  8.             OleDbDataAdapter da = new OleDbDataAdapter("SELECT *FROM CMRS_BUSINESSAREA_MASTER","Provider=MSDAORA.1;User ID=meter_reading;Password=colony;Data Source=windev;OLEDB.NET=true;" );
  9.             DataSet ds = new DataSet();
  10.             da.Fill(ds,"CMRS_BUSINESSAREA_MASTER");
  11.             DataGrid1.DataSource = ds.Tables["CMRS_BUSINESSAREA_MASTER"].DefaultView ;
  12.             DataGrid1.DataBind();
  13.         }
  14.  
  15.  
  16.         public void BindData()
  17.         {
  18.             OleDbDataAdapter da = new OleDbDataAdapter("SELECT *FROM CMRS_BUSINESSAREA_MASTER","Provider=MSDAORA.1;User ID=meter_reading;Password=colony;Data Source=windev;OLEDB.NET=true;" ); 
  19.             DataSet ds = new DataSet(); 
  20.             da.Fill(ds);
  21.  
  22.             DataGrid1.DataSource = ds.Tables[0].DefaultView ;
  23.             DataGrid1.DataBind();
  24.  
  25.  
  26.         }
  27. private void addbtn_Click(object sender, System.EventArgs e)
  28.         {
  29.             string str = ConfigurationSettings.AppSettings["ConnectionString"].ToString();  
  30.  
  31.             OleDbConnection con1 = new OleDbConnection();
  32.             con1.ConnectionString = str;
  33.             OleDbCommand cmd = new OleDbCommand("Insert into cmrs_businessarea_master values('"+TextBox1.Text+"','"+TextBox2.Text+"')",con1);         
  34.             con1.Open();
  35.             cmd.ExecuteNonQuery();
  36.             con1.Close();
  37.             BindData();
  38.  
  39.  
  40.         }
  41. private void updtbtn_Click(object sender, System.EventArgs e)
  42.         {
  43.  
  44.         }
  45.  
  46.         private void delbtn_Click(object sender, System.EventArgs e)
  47.         {
  48.  
  49.         }
Thanks In advance and regards
geetesh
Aug 6 '07 #1
1 2013
radcaesar
759 Expert 512MB
Since u have got the values in TextBox, Store the RowIndex when click and update that using that PrimaryKey Value.
Aug 6 '07 #2

Post your reply

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

Similar topics

reply views Thread by irene | last post: by
2 posts views Thread by Manish | last post: by
25 posts views Thread by Neo Geshel | last post: by
6 posts views Thread by Frank | last post: by
5 posts views Thread by Stephen Plotnick | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.