如何从gridview下面的单选按钮列表中访问方法后面的代码?在这里不允许使用代码块。
<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>
答案 0 :(得分:1)
我认为这是不可能的(仅在具有DataBinding事件的对象上支持数据绑定表达式)。您可以在代码隐藏中设置Text。 例如:
<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>
代码隐藏:
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