0

Hi,

I have a Gridview on Default.aspx. There is a ButtonField (Button Type: Button) on the Gridview1. When user click on any button of ButtonField, I want to show a pop-up of size 500x400 px with a Label, a Textbox and a Button.

Please help me in achieving this as I have got stuck here.

Please post your reply in C# only.

Thanks,
Jatin

3
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by sundarchum
0

Hi,

I have a Gridview on Default.aspx. There is a ButtonField (Button Type: Button) on the Gridview1. When user click on any button of ButtonField, I want to show a pop-up of size 500x400 px with a Label, a Textbox and a Button.

Please help me in achieving this as I have got stuck here.

Please post your reply in C# only.

Thanks,
Jatin

Hi Jatin,

As guru_sarkar said you need to convert the ButtonField to TemplateField with normal button control. Then add the OnClick event of the button (eg. btnOpenPopUp_Click) which is placed inside the TemplateField in source of the aspx page. Then in code behind add the onclick event for the button and add few lines of code. Check with the sample mentioned below.

<asp:TemplateField HeaderText="Click for Popup">
    <ItemTemplate>
        <asp:Button ID="btnOpenPopUp" runat="server" AutoPostBack="true" OnClick="btnOpenPopUp_Click"></asp:Button>
    </ItemTemplate>
</asp:TemplateField>

protected void btnOpenPopUp_Click(object sender, System.EventArgs e)
{
    Response.Write("<script language=\"javascript\" type=\"text/javascript\"> window.open('popup.aspx', '_blank','width=400,height=400');"</script>");
}

Hope this helps better.

Mark as "solved" if this helps to solve your requirement.

Note: Know More

Another one to know is if you have some dropdown in grid and on selecting some value in it you need to display other value or do some thing based on value selected in the dropdown inside the grid you can use the sample code mentioned below.

protected void ddlUpdateStatus_Click(object sender, System.EventArgs e)
{
         DropDownList ddlUpdateStatus = new DropDownList();
         Label lblDueDate = new Label();

    // Get reference to the row in which the button was clicked
    GridViewRow gvr = (GridViewRow)((Control)sender).NamingContainer;

    // Get the reference of Update Status DropDownlist
    ddlUpdateStatus = (DropDownList)gvr.FindControl("ddlUpdateStatus");
    lblDueDate = (Label)gvr.FindControl("lblDueDate");

    if (ddlUpdateStatus.SelectedItem.Value == "U")
         {
        lblDueDate.Text = "DueDate Updated";
    } else {
        lblDueDate.Text = "DueDate Update Failed";
    }
}

Edited by Reverend Jim: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.