Hi,
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
Hi,
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
Are you using C# or VB?
Hi,
I am using vb as code behind.
<asp:DataGrid ID="grdData" runat="server" AutoGenerateColumns="False"
ShowFooter="True">
<Columns>
<asp:TemplateColumn HeaderText="ServiceName">
<ItemTemplate>
<asp:Label ID="lblRank" runat="server" text='<%# eval("services_desc") %>'></asp:Label>
</ItemTemplate>
<HeaderTemplate><center>
<asp:Label ID="hlbl" runat="server" Text="Services"></asp:Label><br />
<asp:DropDownList ID="ddlRank2" runat="server" DataTextField="service"
DataValueField="code">
</asp:DropDownList></center>
</HeaderTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton runat="server" ID="lnkDelete" Text="Delete" CommandName="Delete"></asp:LinkButton>
</ItemTemplate>
<HeaderTemplate><center>
<asp:LinkButton runat="server" ID="lnkInsert" Text="Insert" CommandName="Insert"></asp:LinkButton></center>
</HeaderTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
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.
Next
i hope it help you.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.