By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,939 Members | 1,638 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,939 IT Pros & Developers. It's quick & easy.

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

P: 16
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 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 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 2003
Expand|Select|Wrap|Line Numbers
  1. private void Page_Load(object sender, System.EventArgs e)
  2.         {
  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.         }
  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);
  22.             DataGrid1.DataSource = ds.Tables[0].DefaultView ;
  23.             DataGrid1.DataBind();
  26.         }
  27. private void addbtn_Click(object sender, System.EventArgs e)
  28.         {
  29.             string str = ConfigurationSettings.AppSettings["ConnectionString"].ToString();  
  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();
  40.         }
  41. private void updtbtn_Click(object sender, System.EventArgs e)
  42.         {
  44.         }
  46.         private void delbtn_Click(object sender, System.EventArgs e)
  47.         {
  49.         }
Thanks In advance and regards
Aug 6 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 759
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.