Click here to Skip to main content
11,573,408 members (58,203 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hello,

I have display 3 column in datagridview named id,data1,data2. Now I have problem that i want to id column and then there is 1 link button in gridview.

When I click on that button at that time in "rowdeleting" event i want value of id from that row.

Kindly help me.

Thanks in advance.
Posted 22-Apr-11 7:47am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

The following code snippet will to hide the value associated with gridview column.
<asp:GridView ID="gvData" runat="server"
                            AutoGenerateColumns="False" EmptyDataText="There are no data records to display."
                            CellPadding="4" ForeColor="#333333" GridLines="None" Width="100%" Height="272px" Style="font-family: Consolas">
                            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                            <Columns>
                                <asp:TemplateField HeaderText="Data 1">
                                    <ItemTemplate>
                                        <asp:Label ID="lblId" runat="server" Text='<%# Bind("id") %>' Visible="false"></asp:Label>
                                        <asp:Label ID="lblData1" runat="server" Text='<%# Bind("data1") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Data 2">
                                    <ItemTemplate>
                                        <asp:Label ID="lblData2" runat="server" Text='<%# Bind("data2") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>

The id column is associated with non visible label. So you can access the data that is binded with this label.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

Use this code

<asp:GridView ID="GridView1" runat="server" CssClass="GridViewStyle"
        DataKeyNames="id" AutoGenerateColumns="False" OnRowDeleting="DeleteRecord"
               AllowPaging="True" AllowSorting="true" PageSize="15"
          OnPageIndexChanging="ChangePage" OnSorting="SortRecords">
            
           <Columns>
           <asp:BoundField DataField="id" HeaderText="S No" ReadOnly="True"  SortExpression="id" Visible="false" />
  Permalink  
Comments
digimanus at 7-Sep-11 6:37am
   
DataKeyNames is indeed THE solution
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Just give its width to 0%.

Hope this can help you.
  Permalink  
Comments
uvp_07ce41 at 23-Apr-11 0:55am
   
frnd still it shows tht column.

is there any another solution?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can get the row by using the GridViewDeletedEventArgs.RowIndex and from the row access the cell.
void GridView_RowDeleted(Object sender, GridViewDeletedEventArgs e)
{
    int id = gridView.Rows[e.RowIndex].Cells["id"].Text;
}
  Permalink  
Comments
uvp_07ce41 at 23-Apr-11 0:45am
   
but frnd i want to hide id columan and then also i want value of id when that row selected. in rowdeleting event
Tarakeshwar Reddy at 23-Apr-11 0:56am
   
You can follow what Prasanta_Prince said to hide your row.
uvp_07ce41 at 23-Apr-11 1:48am
   
but its not working. When i make it width to 0 still it display that column.

Is there any another solution?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

This is the code snippet, you can enhance and use as you require. Just handle the row-editing event in code-behind.

<pre lang="xml">asp:GridView ID="gvwTest" runat="server" CssClass="display" AutoGenerateColumns="False" DataKeyNames="id" OnRowEditing="gvwTest_RowEditing" Width="100%">
    <columns>
        <asp:boundfield datafield="code" headertext="Code" itemstyle-width="75px" xmlns:asp="#unknown" />
        <asp:boundfield datafield="name" headertext="Name" xmlns:asp="#unknown" />
        <asp:commandfield showeditbutton="True" itemstyle-width="50px" xmlns:asp="#unknown" />
    </columns
>
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

better solution for this is
i think

hiddenfield it will work fine
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


Advertise | Privacy | Mobile
Web04 | 2.8.150624.2 | Last Updated 7 Sep 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100