Cannot find column after sort

Discussion in 'ASP .Net' started by Allan, Jul 18, 2008.

  1. Allan

    Allan Guest

    Hi,
    I am having trouble when I dynamically assign sqldatasources to a gridview.
    If I do not sort the gridviews, everything runs well even when I change the
    gridview's sqldatasource by changing the dropdownbox. However, after I sort
    the gridview by clicking the B column generated by SDS1 then change to SDS2,
    error message will be "Cannot find column B". Does any one have ideas about
    this?

    Here is the simplified code:

    ASPX

    1 <%@ Page Language="C#"
    2 AutoEventWireup="true"
    3 CodeFile="WiredTest.aspx.cs"
    4 Inherits="WiredTest" %>
    5
    6 <html xmlns="http://www.w3.org/1999/xhtml">
    7 <head>
    8 <title>Untitled Page</title>
    9 </head>
    10 <body>
    11 <form id="form1" runat="server">
    12 <div>
    13
    14 Which SDS:
    15 <asp:DropDownList ID="ddl_display" runat="server">
    16
    17 <asp:ListItem Value="SDS1">SDS1</asp:ListItem>
    18 <asp:ListItem Value="SDS2">SDS2</asp:ListItem>
    19
    20 </asp:DropDownList>
    21
    22 <asp:LinkButton ID="btn_query" runat="server"
    23 onclick="btn_query_Click">Query</asp:LinkButton>
    24
    25
    26 <br />
    27
    28 <asp:GridView ID="gv_CountyAll" runat="server"
    29 AllowPaging="True" AllowSorting="True" />
    30
    31
    32 <asp:SqlDataSource ID="SDS1" runat="server"
    33 ConnectionString="<%$ ConnectionStrings:CP %>"
    34 SelectCommand="
    35 select 123 as A, 345 as B
    36 union
    37 select 123 , 456
    38 union
    39 select 234 , 567
    40 " />
    41 <asp:SqlDataSource ID="SDS2" runat="server"
    42 ConnectionString="<%$ ConnectionStrings:CP %>"
    43 SelectCommand="
    44 select 123 as A, 456 as C
    45 union
    46 select 234 , 567
    47 union
    48 select 789 , 234 " />
    49 </div>
    50 </form>
    51 </body>
    52 </html>


    Code Behind:1 public partial class WiredTest : System.Web.UI.Page
    2 {
    3 protected void Page_Load(object sender, EventArgs e)
    4 {
    5
    6 }
    7
    8 protected void btn_query_Click(object sender, EventArgs e)
    9 {
    10 gv_CountyAll.DataSourceID = ddl_display.SelectedValue;
    11 }
    12
    13 }
    Thanks,Allan
     
    Allan, Jul 18, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rkk
    Replies:
    9
    Views:
    819
    CBFalconer
    Sep 24, 2006
  2. Sub-sort after sort

    , Nov 2, 2007, in forum: Python
    Replies:
    5
    Views:
    774
    Paul Hankin
    Nov 3, 2007
  3. Navin
    Replies:
    1
    Views:
    705
    Ken Schaefer
    Sep 9, 2003
  4. Replies:
    4
    Views:
    139
    Ted Zlatanov
    Jul 18, 2008
  5. Rick
    Replies:
    0
    Views:
    153
Loading...

Share This Page