0

不知道为什么这如此困难,但我有链接到字段的 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>
4

1 回答 1

0

rblYesNo 在 FormView 内,因此您必须执行以下操作(未经测试):

RadioButton rb = (RadioButton)frmProfiles.Items.FindControl("rblYesNo");
if (rb.SelectedItem.Text == "Yes") etc
于 2013-05-03T21:15:10.447 回答