| Author: victoria 24 May 2007 | Member Level: Gold | Rating: Points: 2 |
can u put on the code here???
|
| Author: kamal kumar das 24 May 2007 | Member Level: Gold | Rating: Points: 2 |
TextBox tbox = new TextBox(); string details,Id; tbox.Text = (e.Item.Cells[3].Controls[0].ToString()); details = tbox.Text;
Id = dgAllergies.DataKeys[e.Item.ItemIndex].ToString();
string sql = "UPDATE PatientAllergies SET details='"+details+"',RecordModified = '"+System.DateTime.Now+"' WHERE id='"+Id+"'"; con = new SqlConnection(strConnection); com = new SqlCommand(sql,con); con.Open(); com.ExecuteNonQuery(); dgAllergies.EditItemIndex = -1; dgAllergies.DataBind(); con.Close();
|
| Author: victoria 24 May 2007 | Member Level: Gold | Rating: Points: 2 |
TextBox tbox = new TextBox(); tbox.Text = (e.Item.Cells[3].Controls[0].ToString()); textbox tnum=new textbox(); tnum.Text = e.Items.cells[0].Text; string sql = "UPDATE PatientAllergies SET details='"+tbox.text+"',RecordModified = '"+System.DateTime.Now+"' WHERE id='"+tnum.Text+"'"; con = new SqlConnection(strConnection); com = new SqlCommand(sql,con); con.Open(); com.ExecuteNonQuery(); con.close(); dgAllergies.EditItemIndex = -1; com.commandtext="select *from patientallergies"; con.open(); dgallergies.datasource=com.executereader(); dgallergies.databind(); con.Close();
|
| Author: kamal kumar das 24 May 2007 | Member Level: Gold | Rating: Points: 2 |
Thanks but It is still giving same result.
|
| Author: kamal kumar das 24 May 2007 | Member Level: Gold | Rating: Points: 2 |
Thanks but It is still giving same result.
|
| Author: kamal kumar das 24 May 2007 | Member Level: Gold | Rating: Points: 2 |
Thanks but It is still giving same result.
|
| Author: victoria 24 May 2007 | Member Level: Gold | Rating: Points: 2 |
let me expalin you clearly...
1.first of all need to add edit,update,cancel button column using property builder.. 2.if you want create bound columns... 3.then check what is placement of id in the datagrid..say here it is 0th column and name 1st,remarks 2nd and address 3rd column ..ok
then add the following code to editcommand..
datagrid1.edititemindex=e.item.itemindex; bind();
then add the following code to updatecommand..
textbox tname=(textbox)e.item.cells[1].controls[0]; textbox trem=(textbox)e.item.cells[2].controls[0]; textbox tadd=(textbox)e.item.cells[3].controls[0]; textbox tnum=new textbox(); tnum.Text=e.item.cells[0].text
string s="update tablename set name='"+tname.textt+"',remarks='"+trem.text+"',address='"+tadd.text+"' where id='"+tnum.text+"'";
then normal execution cmd=new sqlcommand(s,con); con.open(); cmd.executenonquery(); con.close(); datagrid1.edititemindex=-1; bind();
thats it
this will surely work ok apply this to your application
|