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
110 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 29

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.
A phishing scam that claims a recipient’s credit card details have been “suspended” is the latest trend in spoof emails.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

617 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