先前选中时的RadioButtonList databbinding

本文关键字:RadioButtonList databbinding | 更新日期: 2023-09-27 18:12:15

不知道为什么这是如此困难,但我有Yes No单选按钮链接到一个字段。当记录被调用时,我希望在单选按钮中选择记录的答案(是或否)。我的代码不能识别单选按钮的id。任何帮助都将非常感激。代码如下:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" %>
<script runat="server">
protected void frmProfiles_PageIndexChanging(object sender, FormViewPageEventArgs e)
{
RadioButton selectedRadioButton = (RadioButton)sender;
}
protected void onYesNochanged(object sender, EventArgs e)
{
if (rblYesNo.SelectedItem.Text == "yes")
;
else
;
}
</script>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">

<asp:FormView
id="frmProfiles"
DataSourceID="srcProfiles"
DataKeyNames="State"
Runat="server">
<ItemTemplate>
<h1>State: <%# Eval("State") %></h1>
<b>1. Is the SMHA Director/Commissioner a member of the Governor's Cabinet?</b>
<%#Eval("O_1") %>
<br />
<br />
<br />
<br />
<asp:LinkButton
id="lnkEdit"
Text="Edit State Information"
CommandName="Edit"
Runat="server" />
</ItemTemplate>
<EditItemTemplate>
<b>1. Is the SMHA Director/Commissioner a member of the Governor's Cabinet?</b>
<br />
<br />

<asp:Label
id="lblYesNo"
DataSourceID="srcProfiles"
DataKeyNames="State"
AssociatedControlID="rblYesNo"
Runat="server" >
<asp:RadioButtonList id="rblYesNo" 
Runat="server" 
enabled="true" 
OnSelectedIndexChanged="onYesNochanged" >
<asp:ListItem  Text="Yes"    Value="Yes" />
<asp:ListItem  Text="No"    Value="No" />   
</asp:RadioButtonList > 
</asp:Label>     
<br /><br />
|
<asp:LinkButton
id="lnkUpdate"
Text="Update State Information"
CommandName="Update"
Runat="server" />
    |
<asp:LinkButton
id="lnkCancel"
Text="Cancel Update"
CommandName="Cancel"
Runat="server" />
</EditItemTemplate>
</asp:FormView>
<br />
Click on State Initials to go to next page.<br />
<asp:GridView
id="grdState"
DataSourceID="srcNext"
ShowHeader="false"
Runat="server">
<Columns>
<asp:HyperLinkField
DataTextField="State"
DataNavigateUrlFields="State"
DataNavigateUrlFormatString="Org2.aspx?State={0}" />
</Columns>
</asp:GridView>

<asp:AccessDataSource ID="srcProfiles" 
SelectCommand="SELECT State, O_1 FROM [P13Organization]
WHERE State=AG"
UpdateCommand="UPDATE [P13Organization] SET State=@State, O_1=@O_1
WHERE State=@State"
DataFile="K:'3NRI'Profiles'Profiles.mdb"
runat="server">
<SelectParameters>
<asp:QueryStringParameter
Name="State"
QueryStringField="State" />
</SelectParameters>   
</asp:AccessDataSource> 
<asp:AccessDataSource ID="srcNext" 
SelectCommand="SELECT State FROM [P13Organization]
WHERE State=@State"
DataFile="K:'3NRI'Profiles'Profiles.mdb"
runat="server">
<SelectParameters>
<asp:QueryStringParameter
Name="State"
QueryStringField="State" />
</SelectParameters>    
</asp:AccessDataSource> 
</asp:Content>

先前选中时的RadioButtonList databbinding

rblYesNo在FormView中,所以你必须这样做(未测试):

RadioButton rb = (RadioButton)frmProfiles.Items.FindControl("rblYesNo");
if (rb.SelectedItem.Text == "Yes") etc