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
108 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 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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