getting selected row values of data grid using vb.net

‘if datagrid is taking data dynamically from database and if it has 1st col as link button , 2nd col and 3rd col are lables

then in order to take the value selected by clicking on linkbutton into string
The datagrid source looks like this
<asp:datagrid id=”DtgFrmDtls” runat=”server” >
<Columns>
<asp:TemplateColumn HeaderText=”USER ID.”> <ItemTemplate>
<– getting dynamic data from folumn named USER_ID –>
<asp:LinkButton id=”LbUid” runat=”server” Text='<%# DataBinder.Eval(Container, “DataItem.USER_ID”) %>’>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText=”USER ID.”> <ItemTemplate>
<– getting dynamic data from folumn named STATUS –>
<asp:Label id=”LbSts” runat=”server” Text='<%# DataBinder.Eval(Container, “DataItem.STATUS”) %>’>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText=”USER ID.”> <ItemTemplate>
<– getting dynamic data from folumn named ADDRESSS–>
<asp:Label id=”LbSts” runat=”server” Text='<%# DataBinder.Eval(Container, “DataItem.ADDRESSS”) %>’>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>




so to get the selected entire row values when user clicks on link button

we need to write DataGrid1_ItemCommand method to DataGrid control

and inside that we should write

‘ uid is col in datagrid which is in link Button so taking CType method for it and converting it to String

Dim uidd As LinkButton = CType(e.Item.FindControl(“LbUid”), LinkButton)

‘sts

Dim sts As Label = CType(e.Item.FindControl(“LbSts”), Label)

Dim Username As String

Dim Status as String

‘ storing selected value in a datagrid to String variables

Username = uidd.Text.Trim()

Status = sts.Text.Trim()

Advertisements

About kakani santosh kumar

Working as Software Engineer in Prithvi Information Solutions having 3 years of Experience in Dotnet Framework ranging from 1.1 to 3.5
This entry was posted in Programming and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s