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. Advertising

  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



    "Marianne" wrote:

    > 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>
    >
    >
    >
    >
    >
    >
     
    matt_c, May 11, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. keithb
    Replies:
    1
    Views:
    4,343
    PeterKellner
    Jun 10, 2006
  2. Replies:
    0
    Views:
    1,284
  3. jobs
    Replies:
    0
    Views:
    1,519
  4. Bart

    problem with Rowdeleting event

    Bart, Jan 31, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    511
  5. David C
    Replies:
    0
    Views:
    3,440
    David C
    Jan 9, 2009
Loading...

Share This Page