单选按钮列表的数据绑定使用的SelectedValue ......可能吗? [英] Databinding of RadioButtonList using SelectedValue...possible?
问题描述
我数据绑定的GridView的一个对象的数据源。在GridView包含一个TemplateField其中包含与内联定义ListItems的一个单选按钮列表。
我希望能够在RadioButtonList的数据绑定的SelectedValue到同一个基础表与其他网格列,但它不工作!
我有我的语法错误,或者这是不可能的,需要循环code分别选择每行中适当的项目?
< llblgenpro:LLBLGenProDataSource ID =llbComputerApplicationDataContainerType =EntityCollection=服务器>< / llblgenpro:LLBLGenProDataSource>
< ASP:GridView控件ID =gridComputerApps的DataSourceID =llbComputerApplication=服务器的AutoGenerateColumns =FALSE
EmptyDataText =未找到该计算机应用。
的DataKeyNames =ComputerID,的applicationID的EnableViewState =假
风格=BORDER-风格:点缀;边框宽度:瘦
>
<柱体和GT;
< ASP:BoundField的数据字段=的applicationID的HeaderText =应用程序IDSORTEX pression =的applicationID可见=真/>
&LT; ASP:的TemplateField的HeaderText =应用程序Name\"><ItemTemplate><%#Eval(\"Application.ApplicationName\")%></ItemTemplate></asp:TemplateField>
&LT; ASP:的TemplateField的HeaderText =归Name\"><ItemTemplate><%#Eval(\"Application.NormalizedAppName\")%></ItemTemplate></asp:TemplateField>
&LT; ASP:模板列HeaderText=\"Notes\"><ItemTemplate><%#Eval(\"Application.NormalizedNotes\")%></ItemTemplate></asp:TemplateField>
&LT; ASP:的TemplateField&GT;
&LT;&HeaderTemplate中GT;
&LT; / HeaderTemplate中&GT;
&LT;&ItemTemplate中GT;
&LT; ASP:RadioButtonList的SelectedValue的='&LT;%#的eval(RequirementOption)%&GT;' ID =rblRequirementOptionRepeatDirection =水平=服务器&GT;
&LT; ASP:ListItem的值=现在需要的文本=现在需要&GT;&LT; / ASP:ListItem的&GT;
&LT; ASP:ListItem的值=极品总有一天文本=极品总有一天&GT;&LT; / ASP:ListItem的&GT;
&LT; ASP:ListItem的值=不需要文本=不需要&GT;&LT; / ASP:ListItem的&GT;
&LT; / ASP:RadioButtonList的&GT;
&LT; / ItemTemplate中&GT;
&LT; / ASP:的TemplateField&GT;
&LT; ASP:BoundField的数据字段=NormalizedNotes的HeaderText =注意事项可见=FALSE/&GT;
&LT; /专栏&GT;
&LT; / ASP:GridView的&GT;
您有什么应该工作。您是否收到错误?下面是我当前的项目复制工作的例子。我绑定到一个可空位字段 - 所以有一个隐藏列表项,接受空
&LT; ASP:RadioButtonList的=服务器ID =MyRbl的SelectedValue ='&LT;%#绑定(MyRblField)%&GT;'
的CssClass =NormalTextBoxRepeatDirection =水平&GT;
&所述; asp的:列表项值=假文本=否/&GT;
&LT; ASP:ListItem的值=真正的文本=是/&GT;
&LT; ASP:ListItem的值=文本=的风格=显示:无/&GT;
&LT; / ASP:RadioButtonList的&GT;
I am databinding a GridView to an object datasource. The gridview contains a TemplateField which contains a RadioButtonList with ListItems defined inline.
I want to be able to databind the SelectedValue of the RadioButtonList to the same underlying table as the other grid columns, but it doesn't work!
Do I have my syntax wrong, or is this impossible and requires looping code to individually select the proper item in each row?
<llblgenpro:LLBLGenProDataSource ID="llbComputerApplication" DataContainerType="EntityCollection" runat="server"></llblgenpro:LLBLGenProDataSource>
<asp:GridView ID="gridComputerApps" DataSourceID="llbComputerApplication" runat="server" AutoGenerateColumns="False"
EmptyDataText ="NO APPLICATIONS FOUND FOR THIS COMPUTER."
DataKeyNames="ComputerID, ApplicationID" EnableViewState="False"
style="border-style:dotted;border-width:thin"
>
<Columns>
<asp:BoundField DataField="ApplicationID" HeaderText="Application ID" SortExpression="ApplicationID" Visible="True" />
<asp:TemplateField HeaderText="Application Name"><ItemTemplate><%#Eval("Application.ApplicationName")%></ItemTemplate></asp:TemplateField>
<asp:TemplateField HeaderText="Normalized Name"><ItemTemplate><%#Eval("Application.NormalizedAppName")%></ItemTemplate></asp:TemplateField>
<asp:TemplateField HeaderText="Notes"><ItemTemplate><%#Eval("Application.NormalizedNotes")%></ItemTemplate></asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<asp:RadioButtonList SelectedValue='<%#Eval("RequirementOption")%>' ID="rblRequirementOption" RepeatDirection="Horizontal" runat="server">
<asp:ListItem Value="Need Now" Text="Need Now"></asp:ListItem>
<asp:ListItem Value="Need Someday" Text="Need Someday"></asp:ListItem>
<asp:ListItem Value="Do Not Need" Text="Do Not Need"></asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="NormalizedNotes" HeaderText="Notes" Visible="False" />
</Columns>
</asp:GridView>
What you have should work. Are you getting an error? Here's a working example copied from my current project. I'm binding to a nullable bit field - so have a hidden list item to accept the nulls.
<asp:RadioButtonList runat="server" ID="MyRbl" SelectedValue='<%# Bind("MyRblField") %>'
CssClass="NormalTextBox" RepeatDirection="Horizontal">
<asp:ListItem Value="false" Text="No" />
<asp:ListItem Value="true" Text="Yes" />
<asp:ListItem Value="" Text="" style="display: none" />
</asp:RadioButtonList>
这篇关于单选按钮列表的数据绑定使用的SelectedValue ......可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!