我正在使用带有 c# 的 asp.net。我有两个图像按钮:打开和删除。默认情况下,它们被禁用,即imgOpen.Enabled = false; imgDelete.Enabled = false;
。我有一个 GridView,它显示表中的搜索结果。GridView contains a radio button which when selected, should enable Open and delete image button. 如果我不使用 ajax 更新面板,那么每次我选择一个单选按钮时,我的页面都会重新加载,这非常令人不安且不友好。
<asp:TemplateField>
<ItemTemplate>
<asp:UpdatePanel ID="updateRadioButton" runat="server">
<ContentTemplate>
<asp:RadioButton ID="rdoBtnFileOption" runat="server" OnCheckedChanged="rdoBtnFileOption_CheckedChanged" AutoPostBack="true" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rdoBtnFileOption" EventName="CheckedChanged" />
</Triggers>
</asp:UpdatePanel>
</ItemTemplate>
</asp:TemplateField>
protected void rdoBtnFileOption_CheckedChanged(object sender, EventArgs e)
{
imgOpen.Enabled = true;
imgDelete.Enabled = true;
RadioButton curretnRdo = sender as RadioButton;
GridViewRow currentRow = (GridViewRow)curretnRdo.NamingContainer;
int index = currentRow.RowIndex;
try
{
foreach (GridViewRow grv in grdSearchResults.Rows)
{
if (grv.RowType == DataControlRowType.DataRow && grv.RowIndex != index)
{
RadioButton rdo = new RadioButton();
rdo = (RadioButton)(grv.FindControl("rdoBtnFileOption"));
rdo.Checked = false;
}
}
}
catch (Exception ex)
{
form.MessageBox.Show(ex.Message, "Error", form.MessageBoxButtons.OK, form.MessageBoxIcon.Error);
}
}
这两条线对我不起作用。
imgOpen.Enabled = true;
imgDelete.Enabled = true;
请提出任何方法。我希望我很清楚。