I have a RadGrid and several GridBoundColumn. One of the column is State. I want to make the State column to be a hyperlink and when the link is clicked I want it to execute a subroutine called Sub1 in code behind. Sub1 is supposed to retrieve from SQL Server
database a list of all cities based on a particular State using VB .Net. How can that be done (sample)? Thanks.
<telerik:GridBoundColumn DataField="State" UniqueName="State" />
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="Sub1" Text="State" ></asp:LinkButton>
</ItemTemplate>
</telerik:GridTemplateColumn>
Protected Sub Sub1(ByVal sender As Object, ByVal e As System.EventArgs)
HOW CAN I GET THE TEXT OF THE STATE GridBoundColumn HERE?
End Sub
Add an attribute w/ the row index to the link button on the ItemCreated Event
Protected Sub RadGrid1_ItemCreated(sender as object , e as GridItemEventArgs )
if (e.Item is GridDataItem)
Dim item as GridDataItem = DirectCast(e.Item, GridDataItem)
Dim button as LinkButton = item.FindControl("LinkButton1")
button.Attributes.Add("data-index", item.ItemIndex)
end if
End Sub
then get the index from the link button in Sub1, and grab that row from the Grid, and get the value of the state. pardon my vb too..may not be 100%
Dim button as LinkButton = DirectCast(sender, LinkButton)
Dim index as integer = button.Attributes("data-index")
Dim row as GridDataRow = RadGrid1.Rows(index)
Dim state = row.column({{statecolumn}}).findControl("myStateControl")
pinky8
Participant
775 Points
1081 Posts
RadGrid and GridBoundColumn text
Jul 29, 2012 02:42 AM|LINK
I have a RadGrid and several GridBoundColumn. One of the column is State. I want to make the State column to be a hyperlink and when the link is clicked I want it to execute a subroutine called Sub1 in code behind. Sub1 is supposed to retrieve from SQL Server database a list of all cities based on a particular State using VB .Net. How can that be done (sample)? Thanks.
syukna
Participant
779 Points
197 Posts
Re: RadGrid and GridBoundColumn text
Jul 29, 2012 05:09 PM|LINK
I would use a GridHyperlinkColumn ( i think it exists :) ), or use a gridTemplateColumn and put a linkButton in it.
pinky8
Participant
775 Points
1081 Posts
Re: RadGrid and GridBoundColumn text
Jul 29, 2012 05:51 PM|LINK
<telerik:GridBoundColumn DataField="State" UniqueName="State" /> <telerik:GridTemplateColumn> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" OnClick="Sub1" Text="State" ></asp:LinkButton> </ItemTemplate> </telerik:GridTemplateColumn> Protected Sub Sub1(ByVal sender As Object, ByVal e As System.EventArgs) HOW CAN I GET THE TEXT OF THE STATE GridBoundColumn HERE? End Subsyukna
Participant
779 Points
197 Posts
Re: RadGrid and GridBoundColumn text
Jul 29, 2012 06:05 PM|LINK
Add an attribute w/ the row index to the link button on the ItemCreated Event
Protected Sub RadGrid1_ItemCreated(sender as object , e as GridItemEventArgs ) if (e.Item is GridDataItem) Dim item as GridDataItem = DirectCast(e.Item, GridDataItem) Dim button as LinkButton = item.FindControl("LinkButton1") button.Attributes.Add("data-index", item.ItemIndex) end if End Subthen get the index from the link button in Sub1, and grab that row from the Grid, and get the value of the state. pardon my vb too..may not be 100%
Dim button as LinkButton = DirectCast(sender, LinkButton) Dim index as integer = button.Attributes("data-index") Dim row as GridDataRow = RadGrid1.Rows(index) Dim state = row.column({{statecolumn}}).findControl("myStateControl")