I am using DataGrid, Now I want to know to get all values from that Datagrid. How can I acheive.

Thanks in Advance,

Visweswaran V

7 Years
Discussion Span
Last Post by jbisono


I am using vb as code behind.

<asp:DataGrid ID="grdData" runat="server" AutoGenerateColumns="False"
<asp:TemplateColumn HeaderText="ServiceName">
<asp:Label ID="lblRank" runat="server" text='<%# eval("services_desc") %>'></asp:Label>
<asp:Label ID="hlbl" runat="server" Text="Services"></asp:Label><br />
<asp:DropDownList ID="ddlRank2" runat="server" DataTextField="service"
<asp:LinkButton runat="server" ID="lnkDelete" Text="Delete" CommandName="Delete"></asp:LinkButton>
<asp:LinkButton runat="server" ID="lnkInsert" Text="Insert" CommandName="Insert"></asp:LinkButton></center>

The above coding is for datagrid. In that I have one dropdown and insert button in header template.

When I am selecting value in DD then that should be added in datagrid. So far I have done. Now I have a button when I am clicking that button I need to get all row values of datagrid (entire values)


Ok i am assuming that particular button is out of the datagrid in that case in the click event method for that button you'll have something like this.

For Each row As DataGridItem In grdData.Items
'Now this loop will run over each row in the datagrid, but the fact that you are using ItemTemplate you will have to cast in order to get your values.
Dim services_Desc As String = DirectCast(row.FindControl("lblRank"), Label).Text
'Now the variable service_Desc contain the services_desc for that particular row. I am not that good with vb but DirectCast is to cast the control found by the FindControl method to a label and then get the text property. in case you bound the items without ItemTemplate doing row.Cells(0).Text to get the first column text for the first row.

i hope it help you.

Edited by jbisono: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.