我創建了一個空的GridView的會話來填充一個gridview,我創建了一個SqlDataSource的,select語句是這個如何根據
SELECT S.[ID], S.[Survey_Name], S.[Start_Date], S.[End_Date], C.[Category_Name], S.[Username], S.[Audience] FROM [Survey] S
Inner Join
Category C On S.Category_ID = C.ID Where Username = @Username
之後,我挑參數的來源,「會話」和它的Session字段爲「用戶名」,此會話在登錄時填充。當我測試它,並輸入它的用戶名,但運行該程序時,gridview始終爲空。
編輯:我的aspx.page代碼。
<asp:SqlDataSource
ID="SqlDataSource1"
Runat="server"
SelectCommand="SELECT S.[ID], S.[Survey_Name], S.[Start_Date],
S.[End_Date], C.[Category_Name], S.[Username], S.[Audience]
FROM [Survey] S Inner Join Category C
On S.Category_ID = C.ID Where Username = @Username"
SelectCommandType="Text"
ConnectionString="<%$ ConnectionStrings:SurveySystemConnectionString %>">
<SelectParameters>
<asp:SessionParameter Name="Username" DbType="String"
DefaultValue="" SessionField="username"/>
</SelectParameters>
</asp:SqlDataSource>
編輯:我的登錄按鈕
protected void LoginButton_Click(object sender, EventArgs e)
{
lblerror.Visible = false;
SqlConnection conn = DatabaseConnection.GetSurveySystemConnection();
string queryString = "SELECT * FROM [Users] WHERE [email protected] AND Password= @password";
SqlCommand command = new SqlCommand(queryString, conn);
command.Parameters.AddWithValue("@username", UserNameTextBox.Text);
command.Parameters.AddWithValue("@password", PasswordTextBox.Text);
SqlDataReader reader = null;
reader = command.ExecuteReader();
if (reader.Read())
{
Session["Username"] = UserNameTextBox.Text;
Session["Name"] = (string)reader["name"];
Session["UserType"] = (string)reader["UserType"];
Response.Redirect("Home.aspx");
}
Connection.close();
}
確保會議不爲空 – IBRA
我做到了,它不是。 – BasharKH
你如何定義和填充你的GridView? – Andrei