tags:

views:

28

answers:

1

Hi,

How can i access code behind methods from the radiobuttonlist insode the gridview below? Using code blocks is of some reason not allowed here..

<asp:GridView ID="gvChildren" runat="server" DataKeyField="ID">
<Columns>
<asp:TemplateField>
<ItemTemplate>

<asp:RadioButtonList runat="server" ID="rblAccess">
<asp:ListItem Value="0" Text="<%= Get("test") %>"></asp:ListItem>
<asp:ListItem Value="1" Text="<%= Get("test") %>">dfgdfg</asp:ListItem>
<asp:ListItem Value="2" Text="<%= Get("test") %>"></asp:ListItem>
</asp:RadioButtonList>

</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

A: 

I think this is not possible(Databinding expressions are only supported on objects that have a DataBinding event). You could set the Text in codebehind. For example:

<asp:RadioButtonList runat="server" ID="rblAccess">
<asp:ListItem Value="0" ></asp:ListItem>
<asp:ListItem Value="1" ></asp:ListItem>
<asp:ListItem Value="2" ></asp:ListItem>
</asp:RadioButtonList>

Codebehind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
        Me.rblAccess.DataBind()
    End If
End Sub

Private Sub rblAccess_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles rblAccess.DataBound
    For Each item As ListItem In rblAccess.Items
        item.Text = getAccessText(item.Value)
    Next
End Sub

Private Function getAccessText(ByVal value As String) As String
    Return "text for item " & value
End Function
Tim Schmelter
Thank you, that will work.
Tofslus
Not tested, but i think the explicit call to DataBind is not necessary in this case because the List is inside a GridView.You should set the item's text in the RowDataBound-Event of the Gridview instead.
Tim Schmelter