开发者

Access code behind members in radiobuttonlist inside gridview

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开发者_如何学JAVA("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>


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜