GridView rowdeleting - e.Values.Count = 0??

Discussion in 'ASP .Net Datagrid Control' started by Marianne, Apr 17, 2007.

  1. Marianne

    Marianne Guest

    Hi,

    I am using a GridView, no sql or objectdatasource. In the rowdeleting
    event, the event arg e.Values.Count = 0, and the sender.Rows = 0, yet I have
    3 rows and multiple non-key datavalues. Why would these values be 0?

    thanks for any help,
    Marianne

    event code:
    protected void CoBrandsGrid_RowDeleting(object sender,
    GridViewDeleteEventArgs e)
    {

    // Delete the row in the database

    int cobrandID =
    Convert.ToInt32(CoBrandsGrid.DataKeys[(int)e.RowIndex].Value);

    string description = e.Values["Description"].ToString();

    //string description = CoBrandsGrid.Rows[e.RowIndex].Cells[0].Text;

    CobrandData.DeleteCobrand(cobrandID, description);

    CoBrandsGrid.DataSource = CobrandData.LoadCobrands();

    CoBrandsGrid.DataBind();

    }

    aspx code:
    <asp:GridView

    id="CoBrandsGrid"

    autogeneratecolumns="False"

    backcolor="White"

    bordercolor="Transparent"

    width="80%"

    gridlines="None"

    cellpadding="4"

    cellspacing="2"

    borderstyle="None"

    DataKeyNames="CoBrandID"

    EmptyDataText="No Cobrands have been created."

    AlternatingRowStyle-BackColor="#E0E0E0"

    OnRowDataBound="CoBrandsGrid_RowDataBound"

    OnRowDeleting="CoBrandsGrid_RowDeleting"

    EnableViewState="false"

    runat="server" >

    <headerstyle font-bold="True" horizontalalign="Center" forecolor="White"
    cssclass="tableHeaderStyle"

    backcolor="#660000"></headerstyle>

    <footerstyle forecolor="Black" backcolor="#C6C3C6"></footerstyle>

    <columns>

    <asp:boundfield itemstyle-horizontalalign="Left" datafield="Description"
    headertext="CoBrand Description"></asp:boundfield>

    <asp:boundfield itemstyle-horizontalalign="Left" datafield="EnterDate"
    headertext="Created Date"
    dataformatstring="{0:MM/dd/yyyy}"></asp:boundfield>

    <asp:boundfield itemstyle-horizontalalign="Center"
    datafield=""></asp:boundfield>

    <asp:boundfield itemstyle-horizontalalign="Center"
    datafield=""></asp:boundfield>

    <asp:CommandField

    ButtonType="Link"

    DeleteText="Delete"

    ShowDeleteButton="true"

    ControlStyle-CssClass="removeButton"

    ItemStyle-HorizontalAlign="Right"

    />

    </columns>

    </asp:GridView>
     
    Marianne, Apr 17, 2007
    #1
    1. Advertisements

  2. Marianne

    matt_c Guest

    hi,

    the reason e.Values.Count = 0 (and e.Keys.Count = 0 as well) is that you are
    not using a datasource object to bind to the grid.
    When you use the traditional databinding method of calling DataBind()
    method, GridViewDeleteEventArgs.Values and GridViewDeleteEventArgs.Keys are
    not populated.

    you need to access these values using the row index.

    hope this is useful.

    matt
     
    matt_c, May 11, 2007
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.