回发后保持单选按钮上的单选 [英] Keep radio selected on radiobutton after postback
问题描述
Hye ..
自动回发后如何保持HTML输入(无线电)值?
这就是我的系统流程.
我有一个下拉列表(autopostback = true),并根据该下拉列表值在gridview中显示数据.
在gridview中,有HTML输入(无线电),用户只能选择一个选项.然后,他们必须单击选择"按钮以导致出现第二个gridview.
但是,在用户单击选择"按钮之后,我如何保持输入(无线电)处于选中状态?
这是我的代码.我要保持选中状态的输入单选名为gvradio.
Hye..
how do i keep a HTML input(radio) value after autopostback?
This is how my system flows.
I have a dropdownlist (autopostback = true) and will display the data in gridview according to that dropdownlist value.
In the gridview, there are HTML input(radio) where the users must choose only one option. Then, they must click on Choose button to cause second gridview appears.
But how do i want to keep the input(radio) selected after the user click on Choose button?
this is my piece of code. the input radio that i want to keep selected is named as gvradio.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
CellPadding="3" DataKeyNames="IdInstitusi"
DataSourceID="SqlDataSourceAlamatInst" Width="398px" Visible="False">
<RowStyle ForeColor="#000066" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<input name="gvradio" type="radio" enableviewstate="true" value='<%#Eval("IdInstitusi")%>' />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:BoundField DataField="AlamatInstitusi" HeaderText="AlamatInstitusi"
SortExpression="AlamatInstitusi" />
</asp:GridView>
推荐答案
问题似乎是您在页面回发时每次都加载GridView
.
确保只加载一次GridView
.添加如下条件,
The problem seems to be you are loading theGridView
everytime the page postback.
Make sure you load theGridView
only once. Add a condition like below,
if (!IsPostBack)
{
// Load the GridView
}
如果有帮助,请将其标记为答案
Mark it as answer if it is helpful
添加 Runat ="Server" 属性.
add Runat="Server" attribute.
<input name="gvradio" type="radio" enableviewstate="true" runat="server" value='<%#Eval("IdInstitusi")%>' />
尝试Asp RadioList或无线电控件来解决此问题.
Try Asp RadioList or radio control to solve this problem.
这篇关于回发后保持单选按钮上的单选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!