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 7497237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:59:30+00:00 2026-05-29T18:59:30+00:00

I have GridView, which is not auto generating columns. In GridView there are 3

  • 0

I have GridView, which is not auto generating columns. In GridView there are 3 columns: one for Checkbox(to delete selected row from DataTable),
one for edit link button(to edit current row),
and the third one is for showing data from DataTable.

I am binding it from DataTable.
I have a primary key in DataTable.
Now my problem is when I am clicking on edit link button I am not getting primary key(id) from
datatable for selected row in grid view (i think row is not selected when i am clicking on edit link button). I cant take row index to match it with datatable primary key as data bound in GridView is filtered.

What I have tried is, I created one more column in grid view as hidden which is primary key column from DataTable. But for that too I am not getting data in hidden column of row which is clicked for edit.

Someone please help with a new idea, or solution for what i am trying.. thanx in advance.

  • 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-29T18:59:40+00:00Added an answer on May 29, 2026 at 6:59 pm

    Plese try as follow.. for update, selected ID can be got in gv_RowCommand event. For delection [multiple select checbox] check in btnDelete_Click, enter code here

    ————–aspx code——————————–

    <asp:Button ID="btnDelete" runat="server" Text="Delete" 
            onclick="btnDelete_Click" />
        <asp:GridView ID="gv" runat="server" AutoGenerateColumns="False" 
            DataKeyNames="ID" onrowcommand="gv_RowCommand" 
            onrowupdating="gv_RowUpdating">
            <Columns>
                <asp:TemplateField HeaderText="Delete">
                    <ItemTemplate>
                        <asp:CheckBox ID="chkSel" runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Update">
                    <ItemTemplate>
                        <asp:LinkButton runat="server" CommandArgument='<%# Eval("ID") %>' CommandName="Update" text="Update" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="NAME" HeaderText="Name" />
            </Columns>
        </asp:GridView>
    

    —————code behind—————————

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                    BindData();
            }
    
            private void BindData()
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("ID");
                dt.Columns.Add("NAME");
    
                DataRow dr = dt.NewRow();
                dr[0] = "1";
                dr[1] = "James";
                dt.Rows.Add(dr);
    
                dr = dt.NewRow();
                dr[0] = "2";
                dr[1] = "Paul";
                dt.Rows.Add(dr);
    
                dr = dt.NewRow();
                dr[0] = "3";
                dr[1] = "Mary";
                dt.Rows.Add(dr);
    
                dr = dt.NewRow();
                dr[0] = "4";
                dr[1] = "Susan";
                dt.Rows.Add(dr);
    
                gv.DataSource = dt;
                gv.DataBind();
            }
    
            protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
            {
                if (e.CommandName == "Update")
                {
                    string id = e.CommandArgument.ToString();
                }
            }
    
            protected void gv_RowUpdating(object sender, GridViewUpdateEventArgs e)
            {
    
            }
    
            protected void btnDelete_Click(object sender, EventArgs e)
            {
                string idList = "";
    
                for (int i = 0; i < gv.Rows.Count; i++)
                {
                    CheckBox chk = (CheckBox)gv.Rows[i].FindControl("chkSel");
    
                    if (chk != null && chk.Checked)
                        idList += gv.DataKeys[i].Value.ToString() + ",";
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a gridview which has one of the columns as a dropdown. When
I have GridView which I can select a row. I then have a button
I have a gridview which is databound, I want to dynamically add a row
I have a GridView which is databound to an XML Datasource. For one of
I have a GridView in which each row has a custom view. The grid
I have a GridView to which I bind a dataTable that I manually created.
I have a gridview in which there are two elements in each of its
I have a GridView containing records from a table which can be deleted or
I have a gridview which is bound to a DataTable. When I try to
i have a gridview which is populating from sql datasource defined at designed, i

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.