AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 Opening new window on row command of grid view
Posted by Sam on  4/7/2010 8:39:24 AM Category: Asp.Net 2.0
Add to my favorites
Email to friend
Hi All


I am using a grid to display data and this one have a button field name'View'.And onclick on view button i want to open a pop up window.Please help mee....I also need to carry the id what i am taking in the session.

Thnks in adv

Post Your Reply Post New Question

 Viewer's Reply
Open New Window in GridView RowCommand event
Answered By Moderator1 on 4/8/2010 8:32:37 AM
Hi,

Follow the code below,

In the GridView RowCommand Event, write the below code,

string RowId = GridView1.SelectedRow.Cells[3].Text;

string strScript = "<script> ";
strScript += "var newWindow = window.open('History.aspx?=id="+RowId+"', '_blank','height=450, center:yes, width=600, status=no, resizable= yes, menubar=no, toolbar=no, location=yes, scrollbars=no, status=no');";
strScript += "</script>";
Page.RegisterClientScriptBlock("strScript", strScript);
 
Opening new window on row command of grid view
Answered By Sharmeek Parmar on 4/9/2010 6:06:02 AM
I have alreday tried that one and this code is not able to pick the datakey if multiple rows are displaying so i change the code with given below.Now problem is that button is needed two click to open window and when i want it on single click.



protected void gvw_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
Session["k"] = gvw.DataKeys[e.NewSelectedIndex][0].ToString();
foreach (GridViewRow row in gvw.Rows)
{

Button b = (Button)row.FindControl("vw");
b.Attributes.Add("onClick", "javascript:window.open('ViewandUpdateCompany.aspx','m','height=380,width=400,left=280px,top=245px,resizable=yes');return true;");


}

}
 
Opening new window on row command of grid view
Answered By Sharmeek Parmar on 4/9/2010 6:40:30 AM
<asp:GridView ID="gvw" runat="server" AllowPaging="True"
AutoGenerateColumns="false" CssClass="td_gray" EmptyDataText="No data"
HeaderStyle-BackColor="#9FCFFF" Width="100%"
DataKeyNames="Companyid"
onpageindexchanging="gvw_PageIndexChanging" PageSize="5"
onrowcommand="gvw_RowCommand">
<Columns>
<asp:TemplateField HeaderText="Company Name" ItemStyle-Width="20%">
<ItemTemplate>
<asp:Label ID="lbl_companyname" runat="server" Text='<%#Eval("Companyname")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="20%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="City" ItemStyle-Width="10%">
<ItemTemplate>
<asp:Label ID="lbl_city" runat="server" Text='<%#Eval("city")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="10%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Phone No." ItemStyle-Width="15%">
<ItemTemplate>
<asp:Label ID="lbl_phone" runat="server" Text='<%#Eval("phoneno")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="15%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Email-Id" ItemStyle-Width="20%">
<ItemTemplate>
<asp:Label ID="lbl_email" runat="server" Text='<%#Eval("Email")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="15%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Industry" ItemStyle-Width="15%">
<ItemTemplate>
<asp:Label ID="lbl_IndustrySector" runat="server"
Text='<%#Eval("IndustrySector")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="15%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Status" ItemStyle-Width="5%">
<ItemTemplate>
<asp:Label ID="lbl_Status" runat="server" Text='<%#Eval("Status")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="5%" />
</asp:TemplateField>

<asp:TemplateField ItemStyle-Width="15%">
<ItemTemplate>
<asp:button id="vw" runat="server" Text="View & Update" CausesValidation="false" CommandName="View" OnClick="a" CssClass="button_login_d" Width="120px"/>
</ItemTemplate>

<ItemStyle Width="15%" />

</asp:TemplateField>


</Columns>
<HeaderStyle BackColor="#9FCFFF" />
</asp:GridView>




protected void gvw_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "View")
{
Session["k"] = 30;
foreach (GridViewRow row in gvw.Rows)
{

//Button b = (Button)row.FindControl("vw");
//b.Attributes.Add("onClick",);
string strScript = "<script> ";
strScript += "var newWindow = window.open('ViewandUpdateCompany.aspx', '_blank','height=450, center:yes, width=600, status=no, resizable= yes, menubar=no, toolbar=no, location=yes, scrollbars=no, status=no');";
strScript += "</script>";
this.Page.RegisterClientScriptBlock("strScript", strScript);

}
}

}



It is still not running.Please help me.In this example i just tried to supply static data key.Main problem is window.
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
Windows 8: 50 Questions and Answers You Need to Make a Decision (Normally $9.95)
The Art & Science of JavaScript - Free 100 Page Preview!
Oracle Magazine