2014-09-22 45 views
0

我是来自Delphi的Visual Studio的新手。使用SqlDataSource发送一个参数给GridView

我有一个GridVew,链接到一个SqlDataSource,如果不过滤,工作正常。

当我尝试过滤它时,我什么都没有。

这些都是我SelectParameters

<SelectParameters> 
    <asp:ControlParameter ControlID="lblPropertyName" DbType="String" DefaultValue="" Name="strPropertyName" PropertyName="Text" /> 
</SelectParameters> 

在代码背后,Page_Load,我得到我想要的网格由过滤值:

lblPropertyName.Text = strPropertyName; 

似乎无法得到GridView过滤,因为它什么都没带。

有人可以花时间帮助我吗?从您的评论

在源页上添加

编辑的代码:

<SelectParameters> 
     <asp:ControlParameter ControlID="lblPropertyName" DbType="String" DefaultValue="" Name="strPropertyName" PropertyName="Text" /> 
</SelectParameters> 

在后面的代码:

foreach (string propertyName in result) 
{ 
    strPropertyName = propertyName; 
} 
lblPropertyName.Text = strPropertyName; 
+0

你有没有看过MSDN的例子http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.selectparameters(v=vs.110).aspx – MethodMan 2014-09-22 18:31:17

+0

其中是您试图附加到此数据源。 。?显示所有相关的代码请 – MethodMan 2014-09-22 18:34:09

+0

我试图显示代码,它太长了,但会弄清楚。 – 2014-09-22 18:44:41

回答

0

我想你应该尝试这样的:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:conn %>" 
    SelectCommand="SELECT * FROM Table_1 where [col1][email protected]"> 
    <SelectParameters> 
     <asp:ControlParameter ControlID="Label1" Name="col" PropertyName="Text" /> 
    </SelectParameters> 
</asp:SqlDataSource>