Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 845211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:24:42+00:00 2026-05-15T06:24:42+00:00

I have following Gridview: <asp:GridView ID=GridView1 runat=server CssClass=table DataKeyNames=groupId DataSource=<%# dsUserGroupsSelected %> DataMember=Group etc….>

  • 0

I have following Gridview:

<asp:GridView ID="GridView1" runat="server" CssClass="table" DataKeyNames="groupId"
          DataSource="<%# dsUserGroupsSelected %>" DataMember="Group" etc....>

and after firing RowDeleting event handler:

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)

e.Keys is empty. Moreover, in runtime if I check

dsUserGroupsSelected.Group.PrimaryKey

it is poulated with:

{System.Data.DataColumn[1]}
    [0]: {groupId}

so it’s really odd to me. Am I missing something? I have this kind of a workaround:

int groupId = (int)GridView1.DataKeys[e.RowIndex].Value;

which will work just fine, but I just can’t get it why e.Keys (and e.Values) would be empty!? Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:24:43+00:00Added an answer on May 15, 2026 at 6:24 am

    It looks like this behaviour is intentional.

    From http://forums.asp.net/p/1050092/2128091.aspx

    Looking in Reflector at Gridview.HandleDelete(), it appears that
    e.Keys and e.Values are only populated if
    gridview.IsBoundUsingDataSourceID. That is, if you set the DataSource
    in code then none of this will work. Good one, Microsoft! Might have
    been useful to mention that in the help perhaps??!! Lachlan

    Edit:

    I ended up making my own data objects and put them in the app_code folder

    ex.

    public class CustomDataViews
    {
        public class FileQuery
        {
            public class File
            {
                public DateTime CreatedDate { get; set; }
                public string FileName { get; set; }
                public string Path { get; set; }
                public void Delete() { }
            }
    
            public ArrayList GetFiles()
            {
                System.Collections.ArrayList files = new ArrayList();
                System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(HttpContext.Current.Server.MapPath("~/UserUpload/"));
                foreach (System.IO.FileInfo fi in (from a in di.GetFiles() orderby a.CreationTime descending select a))
                {
                    File myFile = new File();
                    myFile.CreatedDate = fi.CreationTime;
                    myFile.FileName = fi.Name;
                    myFile.Path = "/VACWeb/UserUpload/" + fi.Name;
                    files.Add(myFile);
                }
                return files;
            }
    
            public void Delete(string FileName)
            {
                if (FileName != null)
                {
                    string path = HttpContext.Current.Server.MapPath("~/UserUpload/") + FileName;
                    if (System.IO.File.Exists(path))
                        System.IO.File.Delete(path);
                }
            }
        }
    }
    

    aspx

    <asp:GridView ID="gvFiles" runat="server" AutoGenerateColumns="False" DataKeyNames="FileName"
        DataSourceID="ods1">
        <Columns>
            <cc:ExtendedCommandField DeleteConfirmationText="Are you sure you wish to delete this file?"
                DeleteText="Delete" ShowDeleteButton="true" />
            <asp:BoundField DataField="CreatedDate" HeaderText="Created Date" DataFormatString="{0:MM/dd/yyyy}" />
            <asp:BoundField DataField="FileName" HeaderText="File Name" />
            <asp:ImageField DataImageUrlField="Path" AlternateText="No Image" HeaderText="Image Preview"
                ControlStyle-Width="100px">
                <ControlStyle Width="100px" />
            </asp:ImageField>
            <asp:BoundField DataField="Path" HeaderText="Path" />
            <asp:HyperLinkField DataNavigateUrlFields="Path" DataTextField="FileName" HeaderText="Link" />
        </Columns>
    </asp:GridView>
    <asp:ObjectDataSource ID="ods1" runat="server" DeleteMethod="Delete" SelectMethod="GetFiles"
        TypeName="CustomDataViews+FileQuery">
        <DeleteParameters>
            <asp:Parameter Name="FileName" Type="String" />
        </DeleteParameters>
    </asp:ObjectDataSource>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following aspx: <asp:GridView ID=GridView1 runat=server AutoGenerateColumns=False BorderStyle=None Font-Names=Verdana Font-Size=12px OnSelectedIndexChanged=GridView1_SelectedIndexChanged ShowHeader=False
I have a simple gridview <asp:GridView ID=GridView1 runat=server DataKeyNames=OriginatorID AutoGenerateColumns=False AllowPaging=True OnPageIndexChanging=GridView1_PageIndexChanging PageSize=5 OnPreRender=GridView1_PreRender>
i have a gridview table like this... <div> <asp:GridView ID=GridView1 runat=server AllowSorting=true OnSorting=TaskGridView_Sorting >
i have the following gridview <asp:GridView ID=GridView3 runat=server AllowPaging=True AllowSorting=True AutoGenerateColumns=False DataKeyNames=ID DataSourceID=CommentsDataSource> <Columns>
I use the following code to display a tooltip <asp:GridView ID=GridView1 runat=server AutoGenerateColumns=False DataKeyNames=ID
I have the following GridView and ObjectDataSource: <asp:GridView ID=grdTrades runat=server DataSourceID=srcTrades DataKeyNames=tradeId EnablePersistedSelection=true SelectedRowStyle-BackColor=Yellow
I have defined a nested grid view in the following way. <asp:GridView ID=GridView1 runat=server
If I have the following (generic) ASP code: <asp:ObjectDataSource runat=server ID=myODS>...</asp:ObjectDataSource> <asp:GridView runat=server ID=myGV
I have the following GridView in ASP.NET 3.5: <asp:GridView ID=gvTable runat=server AllowSorting=true ShowHeader=true> <Columns>
I have the following GridView <asp:GridView ID=grdImoveis runat=server DataSourceID=dsGrid> <Columns> <asp:BoundField HeaderText=Nome DataField=NomeCompleto />

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.