数据库有多张表,根据查询,将SQL语句传递到数据源,再用GridView绑定,显示结果是动态的某张表的数据,代码如下
SqlDataSource1.SelectCommand = Server.UrlDecode(Request.QueryString["sql"]);GridView1.DataBind();
现在希望GridView视图的特定列的元素可以外连接(通过该列的某个元素的参数)到指定的网页;
由于SQL语句传递过来的,具体显示那张表的数据不知道,也就不知道特定列要显示什么元素,也就绑定不了外连接。
GridView视图代码:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            BackColor="White" BorderColor="#CCCCCC" 
            BorderStyle="None" CssClass="gv" BorderWidth="1px" CellPadding="3" 
            DataSourceID="SqlDataSource1"  Width="454px" 
            onrowdatabound="GridView1_RowDataBound">
            <PagerSettings PageButtonCount="10" Position="Top" />
            <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" Wrap="False" CssClass="gvRow"/>
            <EmptyDataRowStyle Wrap="False" />
            <FooterStyle BackColor="White" ForeColor="#000066" Wrap="False" />
            <PagerTemplate>
                <div>
                <table style="font-size:12px;">
                    <tr>
                    <td style="text-align: right">
                        第<asp:Label ID="lblPageIndex" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>'></asp:Label>页/
                        共<asp:Label ID="lblPageCount" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageCount %>'></asp:Label>页  
                        <asp:LinkButton ID="btnFirst" runat="server" CausesValidation="False" Enabled='<%# ((GridView)Container.Parent.Parent).PageIndex != 0%>'
                            CommandName="Page" Text="首页" CommandArgument="first" OnClick="btnFirst_Click">
                        </asp:LinkButton>
                        <asp:LinkButton ID="btnPrev" runat="server" CausesValidation="False" Enabled='<%# ((GridView)Container.Parent.Parent).PageIndex != 0%>'
                            CommandName="Page" Text="上一页" CommandArgument="prev" onclick="btnFirst_Click">
                        </asp:LinkButton>
                        <asp:LinkButton ID="btnNext" runat="server" CausesValidation="False" Enabled='<%# ((GridView)Container.Parent.Parent).PageIndex != ((GridView)Container.Parent.Parent).PageCount-1%>'
                            CommandName="Page" Text="下一页" CommandArgument="next" OnClick="btnFirst_Click">
                        </asp:LinkButton>
                        <asp:LinkButton ID="btnLast" runat="server" CausesValidation="False" Enabled='<%# ((GridView)Container.Parent.Parent).PageIndex != ((GridView)Container.Parent.Parent).PageCount-1%>'
                            CommandName="Page" Text="尾页" CommandArgument="last" OnClick="btnFirst_Click">
                        </asp:LinkButton>
                        转到第<asp:TextBox ID="txtNewPageIndex" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' Width="20px"></asp:TextBox>页
                        <asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="go" CommandName="Page" Text="GO" OnClick="btnFirst_Click">
                        </asp:LinkButton>  
                        <asp:Button ID="btn_word" runat="server" onclick="btn_word_Click" Text="Word导出" />   
                        <asp:Button ID="btn_execl" runat="server" onclick="btn_execl_Click" Text="Excel导出" />  
                    </td>
                    </tr>
                </table>
                </div>
            </PagerTemplate>
            <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" Wrap="False" CssClass="gvPage"/>
            <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" Wrap="False"  />
            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" Wrap="False" CssClass="gvHeader" />
            <EditRowStyle Wrap="True" CssClass="gvEditRow"/>
            <AlternatingRowStyle Wrap="False" CssClass="gvAlternatingRow" />
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>" 
            ProviderName="<%$ ConnectionStrings:ConnectionString2.ProviderName %>" 
            SelectCommand="">
        </asp:SqlDataSource>