-1
我有一個gridview,我想添加一個按鈕'VIEW',它重定向到(Customers.aspx?CustomerID=
)頁面。每個客戶都有一個ID,每個ID都與一個報告相關聯。我不希望ID顯示在我的GridView中,我希望它隱藏起來。 此外,我希望此按鈕僅在用戶是「管理員」或「銷售人員」類別時才顯示。我有一種方法可以將我的CustomerID綁定到UserCategory以分別爲每個ID生成報告。查看帶if else語句的按鈕
我試着看看其他一些帖子,但我的按鈕由於某種原因沒有重定向。 有人可以幫助我找出我在這裏做錯了什麼,或者如果我失去了一些東西。任何幫助將不勝感激。 謝謝。
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="btnView" runat="server" CausesValidation="false" CommandName="Select" Text="VIEW" />
</ItemTemplate>
<ControlStyle CssClass="button" />
</asp:TemplateField>
protected void btnView(object sender, EventArgs e)
{
Button button = (Button)sender;
GridViewRow row = (GridViewRow)button.NamingContainer;
Label lblCustomerID = (Label)row.FindControl("lblCustomerID");
txtHFUserCategory.Value = Session["UserCategoryPC"].ToString();
String strUserCat = MTProcs.GetSingleDatabaseResult("SELECT tblUsers.UserCategoryID FROM tblUsers WHERE UserID = " + txtHFUserID.Value);
if (strUserCat == "4" || strUserCat == "12")
{
ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open(Customers.aspx?CustomerID=" + lblLeadID.Text + "');", true);
}
}
如何用戶和客戶表在數據庫鏈接添加Visible屬性做呢? – ISHIDA
您需要加入這兩個表格。否則,查詢每一行的子表將不會有效。 – Win
你想在GridView中存在''嗎? (即在列的單元格內),還是希望它只是在某個頁面上?答案將決定您是否需要在GridView上使用'_RowDataBound()'事件處理函數,或者確實只需要頁面上的if-then來顯示或隱藏該按鈕。 –
bradykey