Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > GridView rowdeleting - e.Values.Count = 0??

Reply
Thread Tools

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

 
 
Marianne
Guest
Posts: n/a
 
      04-17-2007
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>





 
Reply With Quote
 
 
 
 
matt_c
Guest
Posts: n/a
 
      05-11-2007
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>
>
>
>
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
i want the code for rowupdating and rowdeleting for gridview control in following cod vensmv85 Software 0 11-14-2009 05:45 AM
Getting data value in GridView.RowDeleting David C ASP .Net 0 01-09-2009 05:59 PM
RowDeleting event not handled .. deletecommand not enough? jobs ASP .Net 0 11-17-2006 03:21 PM
Can't get values from GridView when in the RowDeleting Event ryan.wilkins@paccar.com ASP .Net 0 09-11-2006 10:59 PM
Help: GridView RowCommand Event intercepts RowDeleting Event keithb ASP .Net 1 06-09-2006 11:39 PM



Advertisments