Home > Enterprise >  'Index was out of range. It must not be a negative value and must be smaller than the size of t
'Index was out of range. It must not be a negative value and must be smaller than the size of t

Time:08-03

int secilenıd = GridView1.SelectedIndex;

GridViewRow row = GridView1.Rows[secilenıd];

string sorgu = "DELETE  FROM PersonelBilgileri WHERE PersonelID='" row.Cells[1].Text   "'";

SqlCommand cmd = new SqlCommand();

CodePudding user response:

Cell with index 1 probably won't exist. Check your grid again.

CodePudding user response:

In Gridview Use datakeys in gridview control for better execution

 <asp:GridView ID="GridView1" AllowPaging="false" AutoGenerateColumns="false" PagerStyle-Mode="NumericPages" DataKeyNames="datatableprimarykey"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged" >


//c#
string PersonelID =this.GridView1.DataKeys[this.GridView1.SelectedIndex].Value.ToString()

  • Related