Open popup window on click of linkbutton

(ASP.NET)


Hi,

In this article i placed link button inside the repeater. On the click of the link button, i open the  popup window. The popup window is prepopulated with the current record id.

.aspx page


<asp:Repeater OnItemDataBound="rptr_products_ItemDataBound"  id="rptr_products" runat="server">

  <HeaderTemplate>
<table border="1" width="100%">
<tr>
<th>Product ID</th>
<th>product Name</th>
</tr>
</HeaderTemplate>

<ItemTemplate>
<tr>
<td><asp:LinkButton ID="lnk_productid" runat="server" Text='<%#Eval("ProductID") %>' /></td>
<td><asp:Label ID="lbl_productname" runat="server" Text='<%#Eval("ProductName") %>' /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>

Code Behind:-

  protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    bindRepeater();
                }
            }
            catch (Exception)
            { }
        }

        private void bindRepeater()
        {
            try
            {

                SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["Northwindconstring"].ToString());

                string query = "select * from Products";

                DataSet ds = new DataSet();

                SqlDataAdapter sqldt = new SqlDataAdapter(query, sqlcon);
                sqldt.Fill(ds);

                rptr_products.DataSource = ds;
                rptr_products.DataBind();
            }
            catch (Exception)
            { }
        }

        protected void rptr_products_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            try
            {
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    LinkButton lnk = e.Item.FindControl("lnk_productid") as LinkButton;
                    if (lnk != null)
                    {
                        string url = "ProductPoup.aspx?ProductID=" + lnk.Text;

                        lnk.Attributes.Add("onClick", "JavaScript: window.open('" + url + "','','_blank')");
                    }

                }
            }
            catch (Exception)
            { }
        }


Image

Ratings


Average Rating: 0.00 by 0 users
Giri Prasad
6/20/2013
6/20/2013
Download PDF

Comments