Solved

How do I change my asp:GridView contents when I change my selected item in an asp:DropDownList?

Posted on 2014-01-17
3
103 Views
Last Modified: 2015-02-02
When I select a new item in my asp:DropDownList, I want the data in my asp:GridView to reflect info based on the newly selected item in my asp:DropDownList.

I'm using VS2012, .NET Framework 4.5 and C# (HTML 5.0 and CSS 3.0)

Seems like it should be simple ;-) ... please help me understand what I am missing!!

Thanks in advance:

Here's my C# codebehind, followed by my aspx with an Ajax Update Panel, dropdown, and gridview...

my aspx.cs:

protected void ddlTaskList_SelectedIndexChanged(object sender, EventArgs e)
{
    //dsMail.UpdateParameters
    //lblCreateDistList.Visible = true;
    dsMail.UpdateParameters.Add("@TaskID", DbType.Int32, ddlTaskList.SelectedValue);
    grdEmails.DataSource= dsMail;
    grdEmails.DataBind();


}

Open in new window

my aspx:

   
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <Triggers>
            <asp:asyncpostbacktrigger controlid="ddlTaskList" eventname="SelectedIndexChanged" />
        </Triggers>
    <ContentTemplate>
        <asp:DropDownList ID="ddlTaskList" AutoPostBack="true" OnSelectedIndexChanged="ddlTaskList_SelectedIndexChanged" runat="server"></asp:DropDownList>

        <asp:SqlDataSource ID="dsMail" runat="server" SelectCommandType="StoredProcedure" ConnectionString="<%$ ConnectionStrings:EagleEyeConnectionString %>" SelectCommand="stpGetEmailDataByTaskID">
            <SelectParameters>
                <asp:FormParameter DefaultValue="1" FormField="ddlTaskList.DataValueField" Name="TaskID" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:GridView ID="grdEmails" Runat="server" 
            AutoGenerateColumns="False" 
            SkinID="Professional">
            <Columns>
                <asp:HyperLinkField HeaderText="NameLnk" DataTextField="Name" DataNavigateUrlFields="Name" 
                    DataNavigateUrlFormatString="#?Name={0} " />
                <asp:BoundField DataField="TaskDesc" HeaderText="TaskDesc" ReadOnly="True" SortExpression="TaskDesc" />
            </Columns>
        </asp:GridView>

      </ContentTemplate>
  </asp:UpdatePanel>

Open in new window

0
Comment
Question by:aflcio-hit
3 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 39790645
Since you already have dropdownlist bound as a selectparameter for the grid, you should only need to call DataBind() on the grid. There should be no need to alter the datasource at all.
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 39790669
I would just add AppendDataBoundItems="True" to the dropdownlist.

        <asp:DropDownList ID="ddlTaskList" AutoPostBack="true" OnSelectedIndexChanged="ddlTaskList_SelectedIndexChanged" runat="server" AppendDataBoundItems="True"></asp:DropDownList>

Open in new window

0
 

Author Closing Comment

by:aflcio-hit
ID: 40584561
Thanks. Sorry for the slow response.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Running classic asp applications under Windows Server 2008 R2 (x64) and IIS 7 is not as easy as one may think. It took me a while to figure it out while getting error 8002801d a few times. After you install the OS you will need to install the fol…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now