如何从html标记内获取文本框值

时间:2010-07-19 06:14:34

标签: c# asp.net sqldatasource parameterized-query

我想使用TextBox1值从SqlDataSource标签中选择数据到gridview。如何修改文件背后的ASP.net代码。

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
SelectCommand= "select distinct [Species],[qty],[received],[Discard],[mortility],[dispatch],[dispatch],[dpt_sales] from  [vw_getFishDtls] where [Tank_id]=TextBox1.Text and [ftype] =(select [ftype] from [vw_getFishType] where [Tank_id]=TextBox1.Text"
ConnectionString="Data Source=IT-ISHAN;Initial Catalog=ETF;User Id=ishanuk77; Password=ishanuk77;">
</asp:SqlDataSource>

1 个答案:

答案 0 :(得分:0)

您可以添加ControlParameter,如下所示

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
SelectCommand= "select distinct [Species],[qty],[received],[Discard],[mortility],[dispatch],[dispatch],[dpt_sales] from  [vw_getFishDtls] where [Tank_id]=TextBox1.Text and [ftype] =(select [ftype] from [vw_getFishType] where [Tank_id]=@Tank_id"
ConnectionString="Data Source=IT-ISHAN;Initial Catalog=ETF;User Id=ishanuk77; Password=ishanuk77;">
    <SelectParameters>
        <asp:ControlParameter ControlID="TextBox1" Name="Tank_id"
            PropertyName="Text" />
    </SelectParameters>
</asp:SqlDataSource>