471,066 Members | 1,114 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

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="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
Jul 18 '08 #1
0 1513

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Arjen | last post: by
reply views Thread by Kuidros via DotNetMonster.com | last post: by
4 posts views Thread by Aaron Smith | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.