I need to be able to find the row id value of the datasource in my gridview I was using telerik so i would have used the following code to acccess it but im ripping out the telerik controls for bootstrap so using gridview again as the tables works well with it .
<asp:EntityDataSource ID="entPlayers" runat="server" ConnectionString="name=soccerEntities" DefaultContainerName="soccerEntities" EnableFlattening="False" EntitySetName="players" Select="it.[Name], it.[player_id], it.[address], it.[town], it.[gender], it.[zipcode], it.[telephone], it.[email], it.[active], it.[createdDate], it.[dob], it.[teamId]"></asp:EntityDataSource><asp:GridView ID="grdSoccerPlayers" runat="server" CssClass="table-responsive" AutoGenerateColumns="False" DataSourceID="entPlayers" OnRowCommand="grdSoccerPlayers_RowCommand"><Columns><asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True" SortExpression="Name" /><asp:BoundField DataField="player_id" HeaderText="player_id" ReadOnly="True" SortExpression="player_id" /><asp:BoundField DataField="address" HeaderText="address" ReadOnly="True" SortExpression="address" /><asp:BoundField DataField="town" HeaderText="town" ReadOnly="True" SortExpression="town" /><asp:BoundField DataField="gender" HeaderText="gender" ReadOnly="True" SortExpression="gender" /><asp:BoundField DataField="zipcode" HeaderText="zipcode" ReadOnly="True" SortExpression="zipcode" /><asp:BoundField DataField="telephone" HeaderText="telephone" ReadOnly="True" SortExpression="telephone" /><asp:BoundField DataField="email" HeaderText="email" ReadOnly="True" SortExpression="email" /><asp:CheckBoxField DataField="active" HeaderText="active" ReadOnly="True" SortExpression="active" /><asp:BoundField DataField="createdDate" HeaderText="createdDate" ReadOnly="True" SortExpression="createdDate" /><asp:BoundField DataField="dob" HeaderText="dob" ReadOnly="True" SortExpression="dob" /><asp:BoundField DataField="teamId" HeaderText="teamId" ReadOnly="True" SortExpression="teamId" /><asp:ButtonField CommandName="Edit" Text="Edit" /><asp:ButtonField CommandName="Delete" InsertVisible="False" Text="Button" /></Columns></asp:GridView>
How do I in code being access the edit and delete functions
protected void grdSoccerPlayers_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Edit") { // property to an Integer. int index = Convert.ToInt32(e.CommandArgument); // Get the last name of the selected author from the appropriate // cell in the GridView control. GridViewRow = grdSoccerPlayers.Rows[index]; Guid strId = new Guid(item.GetDataKeyValue("id").ToString()); Guid teamId = new Guid(Request.QueryString["teamId"].ToString()); Response.Redirect("edit.aspx?id=" + strId.ToString() + "&teamId=" + teamId.ToString()); } if (e.CommandName == "Delete") { GridDataItem item = e.Item as GridDataItem; Guid strId = new Guid(item.GetDataKeyValue("id").ToString()); player _player = _dal.GetPlayerBYID(strId); _dal.SoccerEntities.Attach(_player); _dal.DeleteObject(_player); _dal.SaveChanges(); grdSoccerPlayers.Rebind(); grdSoccerPlayers.DataBind(); } }
New Gird
<asp:GridView ID="grdSoccerPlayers" runat="server" CssClass="table-responsive" AutoGenerateColumns="False" DataSourceID="entPlayers" OnRowCommand="grdSoccerPlayers_RowCommand"><Columns><asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True" SortExpression="Name" /><asp:BoundField DataField="player_id" HeaderText="player_id" ReadOnly="True" SortExpression="player_id" /><asp:BoundField DataField="address" HeaderText="address" ReadOnly="True" SortExpression="address" /><asp:BoundField DataField="town" HeaderText="town" ReadOnly="True" SortExpression="town" /><asp:BoundField DataField="gender" HeaderText="gender" ReadOnly="True" SortExpression="gender" /><asp:BoundField DataField="zipcode" HeaderText="zipcode" ReadOnly="True" SortExpression="zipcode" /><asp:BoundField DataField="telephone" HeaderText="telephone" ReadOnly="True" SortExpression="telephone" /><asp:BoundField DataField="email" HeaderText="email" ReadOnly="True" SortExpression="email" /><asp:CheckBoxField DataField="active" HeaderText="active" ReadOnly="True" SortExpression="active" /><asp:BoundField DataField="createdDate" HeaderText="createdDate" ReadOnly="True" SortExpression="createdDate" /><asp:BoundField DataField="dob" HeaderText="dob" ReadOnly="True" SortExpression="dob" /><asp:BoundField DataField="teamId" HeaderText="teamId" ReadOnly="True" SortExpression="teamId" /><asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id" /></Columns></asp:GridView>