DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Mon, 16 Apr 2007 21:31:14 -0600,    posted on: microsoft.public.dotnet.framework.aspnet.datagridcontrol        back       

Thread Index
  1    Marianne
          2    matt_c


GridView rowdeleting - e.Values.Count = 0??   
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>
Date:Mon, 16 Apr 2007 21:31:14 -0600   Author:  

RE: GridView rowdeleting - e.Values.Count = 0??   
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>
> 
> 
> 
> 
> 
> 
Date:Thu, 10 May 2007 20:14:01 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us