.net中如何引用TextBox中输入的值

来源:百度知道 编辑:UC知道 时间:2024/09/24 03:32:14
public class ygsel
{
public ygsel()
{

}

/// <summary>
/// 数据库连接字符串
/// </summary>
private static string connectionString = DataBase.GetConnectionString();

/// <summary>
/// 获取名字
/// </summary>
/// <returns></returns>
public static DataTable GetygInfo()
{
DataTable dt = new DataTable();

using(SqlConnection conn = new SqlConnection(connectionString))
{
using(SqlCommand command = new SqlCommand())
{
command.CommandType = CommandType.StoredProcedure ;
//设置查询条件
string sygname = ygname.Text.Trim();//出错

string sygname=((TextBox)this.page.FindControl("textbox的name属性值")).Text

试试这样行不行,应该可以的

你的代码好像不太全,没有看见TextBox的定义语句,不知你用的是.NET的什么版本。其实你可以用关键字 this. 来获取对这个类中对象的访问。如果this.找不到这个TextBox的ID的话,那就说明你这个类里压根就没有定义它,所以我估计这个类是你自己写的,想要调用页面上TextBox的内容?如果是这种情况,建议你把 TextBox的内容 作为一个参数,传入这个类的相应地方法里,而在页面底下调用这个类的方法就行了。

string sygname = TextBox的名字.Text.Trim();

ygname在哪定义的?在第一个页面中定义的吗?