Search code examples
c#asp.netajaxmodalpopupextender

ModalPopupExtender - popup gridview, allow user to select row and populate textbox with columns details


Basically, I have a textbox where a user can enter an ID from a database. To make things easier, the user can popup a GridView using a ModalPopupExtender to display all the tables columns, and they can Select a row, which then closes the modalpopupextender and sets the textbox to the row's ID column.

So far I have this:

     protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string testing = GridView1.SelectedRow.Cells[1].Text.ToString();
        ((TextBox)dtlsInsert.FindControl("txtNom")).Text = GridView1.SelectedRow.Cells[1].Text.ToString();
    }

The 'testing' string gets populated, but it doesn't seem to populate the txtNom textbox. Also, how do I close the modalpopupextender programatically?

Thanks


Solution

  • If GridView1 (and probably its container Panel and the associated ModalPopupExtender) resides in an UpdatePanel, but txtNom does not, txtNom will not be refreshed by partial postbacks triggered by GridView1.

    There are several ways to solve this problem:

    • If you can, put txtNom and GridView1 in the same UpdatePanel.

    • Put txtNom in another UpdatePanel that has its UpdateMode property set to Always.

    • Perform a full postback, by registering GridView1 as a PostBackTrigger in your UpdatePanel.

    Concerning your second question, ModalPopupExtender exposes Show() and Hide() methods on the server side, as well as similar show() and hide() methods on the client side.