R – Subsonic and gridview control delete

asp.netgridviewsubsonic

Does anyone know how to use the gridview delete functionality with Subsonic 3?
I am trying to delete rows that do not have the primary key displayed in the the gridview so I can't just pull that data from the gridview row. I was wondering if there is a way to do it with the DataKeyNames property.

Thanks..

Best Answer

Figured it out:

This is what you do:

<asp:GridView ID="PageGrid" runat="server" OnRowDeleting="DeleteTheRow" AutoGenerateDeleteButton="true"
    AutoGenerateColumns="false" CssClass="centeredTableList" DataKeyNames="page_id">
    <Columns>
        <asp:BoundField DataField="page_name" HeaderText="Page Name" />
        <asp:HyperLinkField Text="Edit" DataNavigateUrlFormatString="p={0}"
            DataNavigateUrlFields="page_id" HeaderText="Edit"/>
    </Columns>
</asp:GridView>



protected void DeleteTheRow(Object sender, GridViewDeleteEventArgs e)
{
    int i = Convert.ToInt32(PageGrid.DataKeys[e.RowIndex].Value);    
}
Related Topic