0
我的搜索功能無法正常工作。不知道我錯了哪裏。C#Gridview搜索
我的代碼是
public partial class _Default : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=foc; Trusted_Connection=yes;");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
Button1_Click(Button1, null);
TextBox1_TextChanged(TextBox1, null);
}
}
protected void BindGrid()
{
DataSet ds = new DataSet();
conn.Open();
string cmdstr = "SELECT MIN([sddoc]) AS[sddoc],[Soldtopt], [tradingname], [REP],MIN([DELTXT]) AS[Preseller Text], SUM(try_cast([Orderqty] as float)) AS[Orderqty],count(distinct Orderqty) as Qtycount , [DlvDate], SUM(try_cast(Netvalue as float)) as Netvalue, count(distinct SDDoc) as Salesdoc , count(distinct case when Netvalue = '0' then 1 else null end) as ZeroValue , count(distinct SDDoc) - count(distinct case when Netvalue = '0' then 1 else null end) As Result FROM [FOC].[dbo].[foc] where dlvdate = @dlvdate GROUP by Soldtopt,tradingname,REP,DlvDate HAVING SUM(try_cast(Netvalue as float)) = 0 and count(distinct SDDoc) = 1 and count(distinct case when Netvalue = '0' then 1 else null end) = 1";
SqlCommand cmd = new SqlCommand(cmdstr, conn);
cmd.Parameters.AddWithValue("@dlvdate", TextBox1.Text);
cmd.ExecuteNonQuery();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(ds);
conn.Close();
gvEmployeeDetails.DataSource = ds;
gvEmployeeDetails.DataBind();
}
protected void gvEmployeeDetails_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblEmpID = (Label)e.Row.FindControl("lblEmpID");
GridView gv_Child = (GridView)e.Row.FindControl("gv_Child");
string txtempid = lblEmpID.Text;
DataSet ds = new DataSet();
conn.Open();
string cmdstr = "Select * from [FOC].[dbo].[foc] where [email protected]";
SqlCommand cmd = new SqlCommand(cmdstr, conn);
cmd.Parameters.AddWithValue("@sddoc", txtempid);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(ds);
cmd.ExecuteNonQuery();
conn.Close();
gv_Child.DataSource = ds;
gv_Child.DataBind();
}
}
「...不工作」不是問題。我們需要詳細信息和錯誤消息來幫助您。 – InteXX
這是網絡表單代碼,而不是MVC(重新標記) –
我正在嘗試搜索gridview數據(dlvdate)。有了這段代碼,我無法通過給出dlvdate來顯示gridview數據。 「(cmd.Parameters.AddWithValue(」@ dlvdate「,TextBox1.Text);」 – Mecido