62,046
社区成员
发帖
与我相关
我的任务
分享
public partial class MasterPage : System.Web.UI.MasterPage
{
public string mpsearchtype
{
get { return DropDownList1.SelectedItem.Value.ToString(); }
}
protected void Button1_Click(object sender, EventArgs e)
{
Server.Transfer("default2.aspx");
}
}
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string searchtype = Master.mpsearchtype;
TextBox mptextbox = (TextBox)Master.FindControl("TextBox1");
DropDownList mpdropdownlist = (DropDownList)Master.FindControl("DropDownList1");
//string searchtype=mpdropdownlist.SelectedItem.Value .ToString();
string searchwhat = mptextbox.Text;
// 1. Create the connection string and command string
string connectionString =
"Data Source=kingdee;Initial Catalog=aspnet;Persist Security Info=True;User ID=;Password=";
string searchtable = "customer";
if (searchtype == "fcustomerid" || searchtype =="fcustomername")
{
searchtable = "customer";
}
string commandString =
"Select * from " + searchtable + " where " + searchtype + " like '%" + searchwhat + "%'";
// 2. Pass the strings to the SqlDataAdapter constructor
SqlDataAdapter dataAdapter =
new SqlDataAdapter(commandString, connectionString);
// 3. Create a DataSet
DataSet dataSet = new DataSet();
// 4. fill the dataset object
dataAdapter.Fill(dataSet, "customer");
// 5. Get the table from the dataset
DataTable dataTable = dataSet.Tables["customer"];
// 6. Bind to the Gridview
GridView1.DataSource = dataTable;
GridView1.DataBind();
}
}
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string searchtype, searchwhat;
//判断是否是跨页面传送,跨页传送就用PreviousPage传值。
if (PreviousPage != null)
{
TextBox mptextbox = (TextBox)PreviousPage.Master.FindControl("TextBox1");
DropDownList mpdropdownlist = (DropDownList)PreviousPage.Master.FindControl("DropDownList1");
searchtype = mpdropdownlist.SelectedItem.Value.ToString();
searchwhat = mptextbox.Text;
}
else
{
searchtype = Master.mpsearchtype;
searchwhat = Master .mpsearchwhat;
}