如何在gridview中传递两个datasourceid。 [英] How to pass two datasourceid in gridview.

查看:69
本文介绍了如何在gridview中传递两个datasourceid。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用sqlDataSource搜索数据但我使用两个sqlDataSource用于不同的存储过程..



我尝试过:



I want to search data using sqlDataSource But I use two sqlDataSource for different Stored Procedure ..

What I have tried:

<asp:GridView runat="server" ID="grdProduct" AutoGenerateColumns="False" CssClass="table table-bordered" ShowHeaderWhenEmpty="True" DataSourceID="dsProduct ,dsBrand ">
......
.....

 <asp:SqlDataSource ID="dsProduct" runat="server" ConnectionString="<%$ ConnectionStrings:connectionRms %>" SelectCommand="Sp_Product_Search" SelectCommandType="StoredProcedure">
                        <SelectParameters>
                            <asp:Parameter DefaultValue="0" Name="Id" Type="Int32" />
                            <asp:ControlParameter ControlID="txtProduct" DefaultValue="All" Name="txtProductName" PropertyName="Text" Type="String" />
                            <asp:Parameter DefaultValue="1" Name="IsActive" Type="Int32" />
                            <asp:Parameter DefaultValue="0" Name="IsDelete" Type="Int32" />
                        </SelectParameters>                        
                    

                    <asp:SqlDataSource ID="dsBrand" runat="server" ConnectionString="<%$ ConnectionStrings:connectionRms %>" SelectCommand="Sp_ProductByBrand_Search" SelectCommandType="StoredProcedure">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="txtProduct" Name="txtBrandName" PropertyName="Text" Type="String" />
                        </SelectParameters>

推荐答案

ConnectionStrings:connectionRms%> SelectCommand = Sp_Product_Search SelectCommandType = StoredProcedure >
< SelectParameters>
< asp:参数DefaultValue = 0名称= Id Type = Int32 />
< asp:ControlParameter ControlID = < span class =code-string> txtProduct DefaultValue = 所有名称= txtProductName PropertyName = Text Type = String />
< asp:参数DefaultValue = 1名称= IsActive Type = Int32 />
< asp:参数DefaultValue = 0 Name = IsDelete Type = Int32 />
< / SelectParameters >


< asp:SqlDataSource ID = dsBrand runat = server ConnectionString = <%
ConnectionStrings:connectionRms %>" SelectCommand="Sp_Product_Search" SelectCommandType="StoredProcedure"> <SelectParameters> <asp:Parameter DefaultValue="0" Name="Id" Type="Int32" /> <asp:ControlParameter ControlID="txtProduct" DefaultValue="All" Name="txtProductName" PropertyName="Text" Type="String" /> <asp:Parameter DefaultValue="1" Name="IsActive" Type="Int32" /> <asp:Parameter DefaultValue="0" Name="IsDelete" Type="Int32" /> </SelectParameters> <asp:SqlDataSource ID="dsBrand" runat="server" ConnectionString="<%


ConnectionStrings:connectionRms%> SelectCommand = Sp_ProductByBrand_Search SelectCommandType = StoredProcedure >
< SelectParameters>
< asp:ControlParameter ControlID = txtProduct Name = txtBrandName PropertyName = 文本类型= 字符串 />
< / SelectParameters >
ConnectionStrings:connectionRms %>" SelectCommand="Sp_ProductByBrand_Search" SelectCommandType="StoredProcedure"> <SelectParameters> <asp:ControlParameter ControlID="txtProduct" Name="txtBrandName" PropertyName="Text" Type="String" /> </SelectParameters>


创建一个新的存储过程,其中包含将两个数据源连接在一起的查询,并将结果作为一个数据集返回。



我认为这会有效,因为你的SqlDataSource控件显示他们有相同的数据库连接,所以它可以直接连接表格。



如果您需要帮助撰写加入项或任何其他帮助,请通知我。
Create a new Stored Procedure which contains a query to join the two data sources together and returns the results as one data set.

I think this will work as your SqlDataSource controls show me they have the same database connection so it will be straight forward to join tables.

If you need help writing the join or any other help let me know.


这篇关于如何在gridview中传递两个datasourceid。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆