Madhukar Krishna

Madhukar Krishna

  • 621
  • 1.4k
  • 292.5k

Update Gridview from code behind without using templates

Mar 18 2015 12:32 PM
I am trying to update gridview from code behind using SQLDataSource. I have not used templates in Gridview. The code is as follows:-
 
void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int index = Convert.ToInt32(e.RowIndex.ToString());
string company1, about1,cmpnytype1, logo1, cntprsn1, website1;
string Telephone1 = GridView1.Rows[index].Cells[5].Text;
logo1= GridView1.Rows[index].Cells[2].Text;
company1 = ((TextBox)(GridView1.Rows[index].Cells[1].Controls[0])).Text;
about1 = ((TextBox)(GridView1.Rows[index].Cells[2].Controls[0])).Text;
cmpnytype1 = ((TextBox)(GridView1.Rows[index].Cells[3].Controls[0])).Text;
logo1 = ((TextBox)GridView1.Rows[index].Cells[4].Controls[0]).Text;
cntprsn1 = ((TextBox)GridView1.Rows[index].Cells[6].Controls[0]).Text;
website1 = ((TextBox)GridView1.Rows[index].Cells[7].Controls[0]).Text;
SqlDataSource1.UpdateParameters["Company_Name"].DefaultValue = company1;
SqlDataSource1.UpdateParameters["About"].DefaultValue = about1;
SqlDataSource1.UpdateParameters["Company_Type"].DefaultValue = cmpnytype1;
SqlDataSource1.UpdateParameters["Logo"].DefaultValue = logo1;
SqlDataSource1.UpdateParameters["Contact_Person"].DefaultValue =cntprsn1;
SqlDataSource1.UpdateParameters["Website"].DefaultValue = website1;
SqlDataSource1.UpdateParameters["Telephone"].DefaultValue = Telephone1;
SqlDataSource1.Update();
GridView1.EditIndex = -1;
bind1();
}
 
The problem is it is not updating. I have referred to this example https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowupdating(v=vs.110).aspx.
 
Please help 
 

Answers (3)