sqldatasourse的值怎么在后台取到? RRS feed

  • 问题

  •     在2个TextBox中输入一前一后的日期,作为SqlDatasource的参数,得到一个值。这个值怎么在c#后台代码中取到呢?

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Try_BackGoundValue_Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <html xmlns="">
    <head runat="server">
        <form id="form1" runat="server">
            <asp:TextBox ID="TextBox_DateFrom" runat="server" AutoPostBack="True"></asp:TextBox>
            <asp:TextBox ID="TextBox_DateTo" runat="server" AutoPostBack="True"></asp:TextBox>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
                SelectCommand="SELECT COUNT(LastName) AS a FROM Employees WHERE (BirthDate &gt; @TimeFrom) AND (BirthDate &lt; @TiemTo)">
                    <asp:ControlParameter ControlID="TextBox_DateFrom" Name="TimeFrom" 
                        PropertyName="Text" />
                    <asp:ControlParameter ControlID="TextBox_DateTo" Name="TiemTo" 
                        PropertyName="Text" />

    C# 菜鸟中的雏鸟!提的问题也许很幼稚,但我是认真的。希望看在党国的面子上拉兄弟一把!

    2013年10月31日 7:53


  • Sorry, I can't input Chinese when using this laptop. There are two methods you can handle it. The first one is through front end. You can click "Configure Data Source", then click "Where". Next, bind the parameter and the control (Textbox). You also need to create a button, names "Search". Then Run it, It's useful.

    Another Method is to write code in the .cs file. Create a SqlDataSource Object, and add the sqlcommand. Then, add parameter which is binding with Textbox.


    2013年10月31日 20:06
  • linjiangxian11:


    Click For donating:Free Rice For the poor
    For spamming-sender issues, you can either report it at Microsoft Spamming Issue, or just find "Report Spam Here+Number" at Forum Issue;You can also find "Verify Your Account+Number" at "Forum Issue", where you can submit to be confirmed to paste links or images.
    For more things to talk about? StackOverFlow is your choice.

    2013年11月1日 3:17
  • 你好,


       1. 首先在HTML Ui设计视图设定SqlDataSource1属性 DataSourceMode="DataReader"


      IDataReader reader = ((IDataReader)((IEnumerable)
                    while (reader.Read())
                        xtname += reader["a"].ToString();

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2013年11月5日 2:03