Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
113 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 2000 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

705 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