如何在gridview中选中复选框时打开弹出窗口? [英] How to open popup window when check box checked in gridview?
问题描述
您好,我正在使用GridView制作电路板。
现在,我想这样做:
1.如果在GridView中选中Checkbox并单击修改按钮,则打开弹出窗口
2.其他警告消息'请检查您的项目'
我点击了代码下方的按钮,当我什么也没选择时,提示信息显示,
我选中了复选框并且按下按钮,也显示提醒信息。没有打开弹出窗口
窗口。
但不是javascript,如果我使用代码
Hello, I` making board using GridView.
And now, I want to make like this :
1. If Checkbox is checked in GridView and click modify Button, open popup windows
2. Else alert message 'Please check your item'
I clicked the button below code, When I choose nothing, alert message showed,
and I checked checkbox and press button, also alert message showed.not opened popup
window.
But instead of javascript , if I use code
Response.Redirect("UserBoard_Edit.aspx?BoardItemID=" + boardItemID);
它运作良好。
我不知道为什么它是没有被解雇...
是否可以制作一个javascript函数?
请帮帮我.. ...
我尝试过:
---这是.aspx页面---
it works well.
I don`t know why It`s not fired...
Is it possible making one javascript function?
Please help me.....
What I have tried:
--- This is .aspx page ---
<asp:LinkButton ID="lnbEdit" runat="server" Text="Edit" OnClick="lnbEdit_Click">
<asp:GridView ID="grvList" DataKeyNames="BoardItemID" runat="server" AutoGenerateColumns="False" >
<columns>
<asp:BoundField HeaderText ="boardItemID" DataField="BoardItemID" HeaderStyle-CssClass="hidden">
<itemstyle cssclass="hidden" />
<asp:BoundField HeaderText="conNo" Visible="false" DataField="indexNo" />
<asp:TemplateField>
<itemtemplate>
<asp:CheckBox ID="chk" runat="server"/>
</itemtemplate>
...
...
</columns>
---这是背后的代码---
--- This is code behind page ---
protected void lnbEdit_Click(object sender, EventArgs e)
{
foreach (GridViewRow gRow in grvList.Rows)
{
CheckBox chk = (CheckBox)gRow.FindControl("chk");
if (chk.Checked)
{
int boardItemID = Convert.ToInt32(gRow.Cells[0].Text);
string popURL = "UserBoard_Edit.aspx?BoardItemID=" + boardItemID;
string openPopUp = @"
<script type='text/javascript'>
popup = window.open('" + popURL + "', 'open_window', 'width = 880, height = 500, left = 0, top = 0'); popup.focus();</script>";
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "script", openPopUp);
//Response.Redirect("UserBoard_Edit.aspx?BoardItemID=" + boardItemID);
}
else
{
string message = @"
<script type='text/javascript'>
alert('Please check your Item');
</script>";
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "script", message);
}
}
}
推荐答案
我勾选复选框并按下按钮,同时显示警告信息。未打开弹出窗口。
and I checked checkbox and press button, also alert message showed.not opened popup window.
看来你的CheckBox Checked
属性总是返回false。您是否尝试过调试代码?
为了确保CheckBox状态不会在每次回发时重置,那么必须在
It seems that your CheckBox Checked
property always returns false. Have you tried debugging your code?
To ensure that the CheckBox state will not reset on each and every postback, then you must bind your GridView within Not IsPostback block in Page_Load
event:
protected void Page_Load(object sender, EventArgs e){
if (!IsPostBack)
{
//Bind Your GridView Here
}
}
这篇关于如何在gridview中选中复选框时打开弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!