Cannot find column after sort

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Allan

    Cannot find column after sort

    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="Wired Test.aspx.cs"
    4 Inherits="Wired Test" %>
    5
    6 <html xmlns="http://www.w3.org/1999/xhtml">
    7 <head>
    8 <title>Untitl ed Page</title>
    9 </head>
    10 <body>
    11 <form id="form1" runat="server">
    12 <div>
    13
    14 Which SDS:
    15 <asp:DropDownLi st ID="ddl_display " runat="server">
    16
    17 <asp:ListItem Value="SDS1">SD S1</asp:ListItem>
    18 <asp:ListItem Value="SDS2">SD S2</asp:ListItem>
    19
    20 </asp:DropDownLis t>
    21
    22 <asp:LinkButt on ID="btn_query" runat="server"
    23 onclick="btn_qu ery_Click">Quer y</asp:LinkButton>
    24
    25
    26 <br />
    27
    28 <asp:GridView ID="gv_CountyAl l" runat="server"
    29 AllowPaging="Tr ue" AllowSorting="T rue" />
    30
    31
    32 <asp:SqlDataSou rce ID="SDS1" runat="server"
    33 ConnectionStrin g="<%$ ConnectionStrin gs: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:SqlDataSou rce ID="SDS2" runat="server"
    42 ConnectionStrin g="<%$ ConnectionStrin gs: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.P age
    2 {
    3 protected void Page_Load(objec t sender, EventArgs e)
    4 {
    5
    6 }
    7
    8 protected void btn_query_Click (object sender, EventArgs e)
    9 {
    10 gv_CountyAll.Da taSourceID = ddl_display.Sel ectedValue;
    11 }
    12
    13 }
    Thanks,Allan


Working...