im having a gridview in only page and on clicking a button column field Gridview1_RowCommand gets executed.What im stuck at is on how to pass a single refno(which is in the grid) to the popup page.i want to use this refno to generate a query help on this will really be appreciated the below code i wat i used and im stuck here..
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
Page.RegisterStartupScript("test", "<script language='javascript'>Openpopup();</script>");
}
<script language='javascript'>
var popupobj;
function Openpopup()
{
popupobj = window.open("popup.aspx", "_blank", "width=1000,height=500,statusbar=no,toolbar=no,scrollbars=no,resizable=no,navbar=no,screenX=800,screenY=800top=100,left=100");
popupobj.focus();
}
</script>
Since you are using RowCommand event, to be able to send this value to the Popup you need to set the RowIndex as a CommandArgument of the Button you are clicking to open the popup. Set the Value(refno) to passed to Popup in DataKey.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
var Button1= e.Row.FindControl("Button1") as Button;
Button1.CommandName = "ButtonClick";
// cast RowIndex in line code to string if e.CommandArgument accepts string
Button1.CommandArgument = e.Row.RowIndex;
}
Now in the RowCommand
protected void GridView1_RowCommand(object sender, GridViewRowCommandArgs e)
{
if(e.CommandName == "ButtonClick")
{
var refno = GridView1.DataKeys[Convert.ToInt32(e.CommandArgument)]["refno"];
Page.RegisterStartupScript("test", "<script language='javascript'>Openpopup(' + refno + ');</script>");
}
}
This way now you have refno in the Javascript function argument. Pass this argument as a querystring in the Javascript popup function.
This way you can access refno in the Popup page.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.