How to popup a Window from a Grid Click Item event Using asp.net C#


Sometimes we get a scenario to update the Information of the Grid Data. With Inline Editing of the Grid the End User will not have visualize the Details properly due to that he may not update his details in that. So when clicking an event in the Grid Command how we need to popup a window . This is the One i need to discuss in this Article here..

Sometimes we get a scenario to update the Information of the Grid Data. With Inline Editing of the Grid the End User will not have visualize the Details properly due to that he may not update his details in that. So when clicking an event in the Grid Command how we need to popup a window . This is the One i need to discuss here.

In this Article i will discuss how to call Client side Script in Server Code . Say i had an Order Information in Grid with that i want to show that data in a popup window in that Grid.

See the Below Snapshot how my Grid looks like..
Popup a Window


So how to achieve this through Coding see the Below Code...

Here is the Html Code for Popup window....


div id="mask"
div
asp:UpdatePanel ID="updateStatus" runat="server" UpdateMode="Always"
ContentTemplate
asp:Panel ID="pnlpopup" runat="server" BackColor="White" CssClass="edit_ordercon"
h3
Edit Order a id="closebtn" style="color: white; float: right; text-decoration: none"
class="btnClose order_closeicon" href="#"a
h3
div class='edit_orderconinner'
ul
li
label
Order Id :label asp:Label ID="ItemName" runat="server"asp:Label li
li
label
Ordered Qty :label asp:Label ID="lblOrderedQty" runat="server" asp:Label li
li
label
Delivered Qty : label asp:Label ID="lblDeleiveredQty" runat="server" asp:Label li
li
label
Amount : labelasp:Label ID="lblAmount" runat="server"asp:Label li
li
label
Shipping Info : label
asp:Label ID="lblShippingInfo" runat="server" asp:Label li
li
label
Status :label
asp:DropDownList ID="ddlStatus" runat="server" CssClass='status_select'
asp:ListItem Text="In Process" Selected="True" Value="0"asp:ListItem
asp:ListItem Text="Shipped" Value="1" asp:ListItem
asp:ListItem Text="Next Day Delivery" Value="2" asp:ListItem
asp:DropDownList
li
li class="tracker_box" id="tracker" runat="server"
label
Tracker# :label asp:TextBox ID="txtTracker" Visible="true" runat="server"asp:TextBoxli
asp:HiddenField ID="HduserName" runat="server"
asp:HiddenField ID="HdBPID" runat="server"
ul
div
div class='edit_orderbutton'
asp:Button ID="btnUpdate" CssClass="ord_button" CommandName="Update" runat="server"
Text="Update" OnClick="btnUpdate_click"
<%-- OnClick="imgButtonShowOrders_Click" style="margin-left: 5px; margin-bottom:20px;"--%>

input id="btnCanceledit" type="button" class="ord_button ord_cancelbutton" value="Cancel"
/div
asp:UpdateProgress ID="UpdateProgress6" runat="server" DisplayAfter="0" AssociatedUpdatePanelID="updateStatus"
ProgressTemplate>
div class="myac2_rbp"
img src="images/indicator.gif" alt="indicator" align="left"
Your request is being processed...Please wait!
div
ProgressTemplate
asp:UpdateProgress
asp:Panel
ContentTemplate
asp:UpdatePanel
div



This is the Script and css code for popup



style type="text/css"
#mask
{
position: fixed;
left: 0px;
top: 0px;
z-index: 4;
opacity: 0.4;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=40)";
filter: alpha(opacity=40);
background-color: gray;
display: none;
width: 100%;
height: 100%;
}
.ddleditaccess_dropdown
{
height: 32px;
border: 1px solid #ccc;
background: #fff;
}
style
script src="js/jquery-1.3.2.min.js" type="text/javascript"script
script type="text/javascript" src="js/jquery-1.3.2.js"script
script type="text/javascript"
<script type="text/javascript"
function ShowPopup() {
$('#mask').show();
$('#<%=pnlpopup.ClientID %>').show();
if ($('.status_select').val() == 1) {
$('#<%=pnlpopup.ClientID %>').find('#<%=tracker.ClientID%>').css('display', 'block');
}
}
function HidePopup() {
$('#mask').hide();
$('#<%=pnlpopup.ClientID %>').hide();
}
$(".btnClose, #btnCanceledit").live('click', function () {
HidePopup();
});

</script>



protected void GridViewPastSummaryOrders_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
Control c = e.CommandSource as Control;
if (c != null)
{
string Cmdname = e.CommandArgument.ToString();
string expression = "WAI_ORDER_NUMBER ='" + Cmdname + "' ";
DataSet dsPastOrders = (DataSet)Session["pastOrders"];
DataRow[] dr = dsPastOrders.Tables[0].Select(expression);

if (dr.Length == 1)
{
ItemName.Text = dr[0].ItemArray[12].ToString();
lblOrderedQty.Text = dr.Length.ToString();
lblDeleiveredQty.Text = dr.Length.ToString();

}
else
{
for (int i = 0; i < dr.Length; i++)
{
ItemName.Text = dr[0].ItemArray[12].ToString();
lblOrderedQty.Text = dr.Length.ToString();
lblDeleiveredQty.Text = dr.Length.ToString();
}

}
if (dr[0].ItemArray[19].ToString() == "1")
{
lblShippingInfo.Text = "Shipped";
}
else
{
lblShippingInfo.Text = "";

}
if (lblShippingInfo.Text.ToUpper().Equals("SHIPPED"))
{
ddlStatus.SelectedIndex = 1;
txtTracker.Text = dr[0].ItemArray[18].ToString();
}

if (dr[0].ItemArray[19].ToString().Contains("2"))
{
ddlStatus.SelectedIndex = 2;
txtTracker.Text = dr[0].ItemArray[18].ToString();
txtTracker.Visible = true;
tracker.Visible = true;

}
else
{
txtTracker.Text = "";
ddlStatus.SelectedIndex = 0;
}

if (dr.Length > 1)
{
for (int i = 0; i < dr.Length; i++)
{
if (dr[i].ItemArray[7].ToString() == "N")
{
Amount = Amount + Convert.ToDouble(dr[i].ItemArray[17].ToString());
}
}

lblAmount.Text = GetUserDisplayCurrency("GBP") + " " + Amount.ToString();
}
else
{
lblAmount.Text = GetUserDisplayCurrency("GBP") + " " + dr[0].ItemArray[17].ToString();
}
HdBPID.Value = dr[0].ItemArray[4].ToString();
HduserName.Value = dr[0].ItemArray[5].ToString();
}

Popup(true);
}
}


void Popup(bool isDisplay)
{
System.Text.StringBuilder builder = new System.Text.StringBuilder();
if (isDisplay)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "ShowPopup();", true);
}
else
{
builder.Append("<script language='JavaScript'> HidePopup(); </script>\n");
Page.ClientScript.RegisterStartupScript(this.GetType(), "HidePopup", builder.ToString());
}
}


Attachments

Article by srirama
A Good advice from parent to a Child , Master to a Student , Scholar to an Ignorant is like a doctor prescribed pill it is bitter to take but when they take it will do all good for them --- Bhushan

Follow srirama or read 74 articles authored by srirama

Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: