请教高手,谁为我比较比较这两段代码

huoqiu412 2008-08-21 01:22:24
前面一段是我自己生成的,后面是从书的随机盘中拷过来的,我深得它们一模一样,但我的就是实现不了功能,为什么呀,第一次载入页面时显示全部记录,以后根据下拉列表筛选显示的记录

第一段代码:
<asp:DropDownList ID="DropDownList1" runat="server"
AutoPostBack="True"
DataSourceID="SqlDataSource2"
DataTextField="state"
DataValueField="state"
AppendDataBoundItems="True">
      <Items>
<asp:ListItem Text="(Choose a state)" />
</Items>
</asp:DropDownList>

<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:LocalSqlPubs %>"
SelectCommand="SELECT DISTINCT [state] FROM [authors]">
</asp:SqlDataSource>

<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="au_id" HeaderText="au_id" ReadOnly="True" SortExpression="au_id" />
<asp:BoundField DataField="au_lname" HeaderText="au_lname" SortExpression="au_lname" />
<asp:BoundField DataField="au_fname" HeaderText="au_fname" SortExpression="au_fname" />
<asp:BoundField DataField="phone" HeaderText="phone" SortExpression="phone" />
<asp:BoundField DataField="address" HeaderText="address" SortExpression="address" />
<asp:BoundField DataField="city" HeaderText="city" SortExpression="city" />
<asp:BoundField DataField="state" HeaderText="state" SortExpression="state" />
<asp:BoundField DataField="zip" HeaderText="zip" SortExpression="zip" />
<asp:CheckBoxField DataField="contract" HeaderText="contract" SortExpression="contract" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:LocalSqlPubs %>"
CancelSelectOnNullParameter="False"
SelectCommand="
SELECT * FROM authors
WHERE state = IsNull(@state,state)"
>
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="state" PropertyName="SelectedValue"
/>
</SelectParameters>
</asp:SqlDataSource>
第二段代码:
<asp:DropDownList ID="DropDownList1" Runat="server"
AppendDataBoundItems="true"
AutoPostBack="True"
DataSourceID="SqlDataSource2"
DataTextField="state"
DataValueField="state">
<Items>
<asp:ListItem Text="(Choose a state)" Value="" />
</Items>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" Runat="server"
SelectCommand="SELECT DISTINCT [state] FROM [authors]"
ConnectionString="<%$ ConnectionStrings:LocalSqlPubs %>"/>
<br />
<br />
<asp:GridView ID="GridView1" Runat="server"
DataSourceID="SqlDataSource1"
AllowSorting="True"
AutoGenerateColumns="False"
AllowPaging="True">
<Columns>
<asp:BoundField HeaderText="au_id" DataField="au_id" SortExpression="au_id" />
<asp:BoundField HeaderText="au_lname" DataField="au_lname" SortExpression="au_lname" />
<asp:BoundField HeaderText="au_fname" DataField="au_fname" SortExpression="au_fname" />
<asp:BoundField HeaderText="phone" DataField="phone" SortExpression="phone" />
<asp:BoundField HeaderText="address" DataField="address" SortExpression="address" />
<asp:BoundField HeaderText="city" DataField="city" SortExpression="city" />
<asp:BoundField HeaderText="state" DataField="state" SortExpression="state" />
<asp:BoundField HeaderText="zip" DataField="zip" SortExpression="zip" />
<asp:CheckBoxField HeaderText="contract" SortExpression="contract" DataField="contract" />
</Columns>
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" Runat="server"
ConnectionString='<%$ ConnectionStrings:LocalSqlPubs %>'
CancelSelectOnNullParameter="false"
SelectCommand="
SELECT * FROM authors
WHERE state = IsNull(@state, state)">
<SelectParameters>
<asp:ControlParameter Name="state"
ControlID="DropDownList1"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
...全文
52 4 打赏 收藏 举报
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
huoqiu412 2008-08-22
奇怪!!在VS2005中执行不正确,但在VS2008中执行就正确了,操作方法是一样的
  • 打赏
  • 举报
回复
LQknife 2008-08-22
代码太长头疼 帮你顶吧
  • 打赏
  • 举报
回复
huoqiu412 2008-08-22
你说的都是形式不一样,我想知道为什么执行起来不一样
  • 打赏
  • 举报
回复
qixi0616 2008-08-21
<asp:DropDownList ID="DropDownList1" Runat="server"
AppendDataBoundItems="true"
AutoPostBack="True"
DataSourceID="SqlDataSource2"
DataTextField="state"
DataValueField="state">
<Items>
<asp:ListItem Text="(Choose a state)" Value="" /> ------------
</Items>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" Runat="server"
SelectCommand="SELECT DISTINCT [state] FROM [authors]"
ConnectionString=" <%$ ConnectionStrings:LocalSqlPubs %>"/> --------
<br />
<br />
<asp:GridView ID="GridView1" Runat="server"
DataSourceID="SqlDataSource1"
AllowSorting="True" -------
AutoGenerateColumns="False"
AllowPaging="True"> --
<Columns>
<asp:BoundField HeaderText="au_id" DataField="au_id" SortExpression="au_id" /> -----------
<asp:BoundField HeaderText="au_lname" DataField="au_lname" SortExpression="au_lname" />
<asp:BoundField HeaderText="au_fname" DataField="au_fname" SortExpression="au_fname" />
<asp:BoundField HeaderText="phone" DataField="phone" SortExpression="phone" />
<asp:BoundField HeaderText="address" DataField="address" SortExpression="address" />
<asp:BoundField HeaderText="city" DataField="city" SortExpression="city" />
<asp:BoundField HeaderText="state" DataField="state" SortExpression="state" />
<asp:BoundField HeaderText="zip" DataField="zip" SortExpression="zip" />
<asp:CheckBoxField HeaderText="contract" SortExpression="contract" DataField="contract" />
</Columns>
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" Runat="server"
ConnectionString=' <%$ ConnectionStrings:LocalSqlPubs %>'
CancelSelectOnNullParameter="false"
SelectCommand="
SELECT * FROM authors
WHERE state = IsNull(@state, state)"> ------------
<SelectParameters>
<asp:ControlParameter Name="state"
ControlID="DropDownList1"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>

不一样的地方有"---------"
  • 打赏
  • 举报
回复
相关推荐
发帖
.NET社区

6.0w+

社区成员

.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • R小R
  • 喵叔哟
加入社区
帖子事件
创建了帖子
2008-08-21 01:22
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。