在我的Asp项目中,我的gridview中有一个单选按钮。单选按钮仅允许用户每次选择一次。
但是,当用户单击单选按钮时,将显示确认消息,并且只有在用户单击“确定”时才会保存记录。
一切正常,但现在我遇到了问题。当用户点击“确定”时,单选按钮oncheckedchanged
似乎不会触发。一旦用户点击“确定”,我该如何触发单选按钮事件?
这是我的代码: 的Javascript
function RadioCheck(rb) {
var gv = document.getElementById('Content_PageContent_ucSubMenuItem_module_sales_customer_submenuitem_contactpersonlist_ascx_gvContactPersonList');var rbs = gv.getElementsByTagName("input");
for (var i = 0; i < rbs.length; i++) {
if (rbs[i].type == "radio") {
//if radio button is check but not the selected value then false
if (rbs[i].checked && rbs[i] != rb) {
rbs[i].checked = false;
break;
}
}
}
return confirm('Confirm Save?');
}
客户端
<asp:TemplateField HeaderText="Default" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:RadioButton ID="rdbtnDefault" runat="server" onclick="RadioCheck(this);" oncheckedchanged="rdbtnDefault_CheckedChanged" Visible='<%#((string)Eval("DEFAULT")) == "Y" ? false : true %>'/>
<asp:Image ID="imgDefault" runat="server" Height="13px" ImageUrl="~/Styles/images/tick-48x48.png" Width="13px" Visible='<% ((string)Eval("DEFAULT")) == "Y" ? true : false %>' />
</ItemTemplate>
服务器端
//--Register for in post back--
if (Page.ClientScript.IsClientScriptBlockRegistered(DataUCContactListing) == false) {
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "gvRdBtnSelectOnce", blcGenerateScript.gvRdBtnSelectOnce(gvContactPersonList.ClientID,true), true);
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "gvSelectAllChkBox", blcGenerateScript.gvSelectAllChkBox(gvContactPersonList.ClientID), true);
}
//**Register for script**
protected void rdbtnDefault_CheckedChanged(object sender, EventArgs e) {
try {
RadioButton lnBTNDone = (RadioButton)sender;
GridViewRow row = (GridViewRow)lnBTNDone.NamingContainer;
string accountID = gvContactPersonList.DataKeys[row.RowIndex].Values[0].ToString();
int contactID = int.Parse(gvContactPersonList.DataKeys[row.RowIndex].Values[1].ToString());
using (TransactionScope scope = new TransactionScope()) {
dlcCustomerDB.updateAccountOtherDefaultN(accountID);
dlcCustomerDB.updateAccountDefaultY(accountID, contactID);
scope.Complete();
}
createGridView();
this.Session[gbcMessageSessionID.message1] = gbcMessageAlert.saveSuccessfully;
Response.Redirect(Request.Url.ToString());
} catch (Exception ex) {
logger.Error(ex.Message);
throw;
}
}
答案 0 :(得分:0)
查看以下网址
http://www.asp.net/web-forms/tutorials/data-access/enhancing-the-gridview/adding-a-gridview-column-of-radio-buttons-vb
Radiobutton checked change event not firing in gridview
请查看此代码
<asp:RadioButton ID="rdbtnDefault" runat="server" onclick="return RadioCheck(this);" oncheckedchanged="rdbtnDefault_CheckedChanged" Visible='<%#((string)Eval("DEFAULT")) == "Y" ? false : true %>' AutoPostBack="True" />
我已添加&#34;返回&#34; RadioButton的onclick事件的关键字。