0
Reply

I'm using Gridview for Delete recorde but i have show error

Rana Asif Naseer

Rana Asif Naseer

Nov 4 2016 3:09 PM
190
Compiler Error Message: CS1061: 'System.Web.UI.WebControls.GridViewDeletedEventArgs' does not contain a definition for 'RowIndex' and no extension method 'RowIndex' accepting a first argument of type 'System.Web.UI.WebControls.GridViewDeletedEventArgs' could be found (are you missing a using directive or an assembly reference?)
Line 223:        string stor_id = Convert.ToInt32(GridView2.DataKeys[e.RowIndex].Values["stor_id"].ToString());
 
DashBoard.aspx
<asp:GridView ID="GridView2" runat="server" Height="180px" Width="1200px" AutoGenerateColumns="False" DataKeyNames="Reg_ID" OnPageIndexChanging="GridView2_PageIndexChanging"
OnRowCancelingEdit="GridView2_RowCancelingEdit" OnRowDeleted="GridView2_RowDeleted" OnRowEditing="GridView2_RowEditing" OnRowUpdating="GridView2_RowUpdating" style="margin-right: 3px">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btn_Edit" runat="server" Text="Edit" CommandName="Edit" />
<asp:Button ID="btn_Delete" runat="server" Text="Delete" CommandName="Delete" />

DashBoard.cs
 
protected void GridView2_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
string stor_id = Convert.ToInt32(GridView2.DataKeys[e.RowIndex].Values["stor_id"].ToString());
con.Open();
SqlCommand cmd1 = new SqlCommand("delete from Teachers_Reg where Reg_ID=" + stor_id, con);
int result = cmd1.ExecuteNonQuery();
con.Close();
if (result == 1)
{
ShowData();
lblmsg.BackColor = Color.Red;
lblmsg.ForeColor = Color.White;
lblmsg.Text = stor_id + " Deleted successfully....... ";
}
}