Grid View DataBindings...
-
Dear Friend I have one Grid contain hyperlink control, i want to set its visibility depend on Login Group, If User is "Guest" then User can not access the link but if that user is "Authorized" he can access that link. For this, i have created following code Form Syntex Level Code:
public partial class frmTest : System.Web.UI.Page
{
private bool IsVisible
{
get { return (Session["G_UserGroup"] == "9") ? true : false; }
}
}Form Design:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="frmTest.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="gvwOrders" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" AllowSorting="True" OnSorting="gvwOrders_Sorting" EnableViewState="False">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="Link">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="http://www.google.com"
Visible='<%# Eval("IsVisible") %>'>Link</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</form>
</body>
</html>I try to use this way as Eval is use to access different properties. Please help me as i m going right way but issue is in syntex. Thanks and regards
sasmi
-
Dear Friend I have one Grid contain hyperlink control, i want to set its visibility depend on Login Group, If User is "Guest" then User can not access the link but if that user is "Authorized" he can access that link. For this, i have created following code Form Syntex Level Code:
public partial class frmTest : System.Web.UI.Page
{
private bool IsVisible
{
get { return (Session["G_UserGroup"] == "9") ? true : false; }
}
}Form Design:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="frmTest.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="gvwOrders" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" AllowSorting="True" OnSorting="gvwOrders_Sorting" EnableViewState="False">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="Link">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="http://www.google.com"
Visible='<%# Eval("IsVisible") %>'>Link</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</form>
</body>
</html>I try to use this way as Eval is use to access different properties. Please help me as i m going right way but issue is in syntex. Thanks and regards
sasmi
yes, it is right, are you facing any problem in this?
-
Dear Friend I have one Grid contain hyperlink control, i want to set its visibility depend on Login Group, If User is "Guest" then User can not access the link but if that user is "Authorized" he can access that link. For this, i have created following code Form Syntex Level Code:
public partial class frmTest : System.Web.UI.Page
{
private bool IsVisible
{
get { return (Session["G_UserGroup"] == "9") ? true : false; }
}
}Form Design:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="frmTest.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="gvwOrders" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" AllowSorting="True" OnSorting="gvwOrders_Sorting" EnableViewState="False">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="Link">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="http://www.google.com"
Visible='<%# Eval("IsVisible") %>'>Link</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</form>
</body>
</html>I try to use this way as Eval is use to access different properties. Please help me as i m going right way but issue is in syntex. Thanks and regards
sasmi
-
Dear Friend I have one Grid contain hyperlink control, i want to set its visibility depend on Login Group, If User is "Guest" then User can not access the link but if that user is "Authorized" he can access that link. For this, i have created following code Form Syntex Level Code:
public partial class frmTest : System.Web.UI.Page
{
private bool IsVisible
{
get { return (Session["G_UserGroup"] == "9") ? true : false; }
}
}Form Design:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="frmTest.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="gvwOrders" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" AllowSorting="True" OnSorting="gvwOrders_Sorting" EnableViewState="False">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="Link">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="http://www.google.com"
Visible='<%# Eval("IsVisible") %>'>Link</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</form>
</body>
</html>I try to use this way as Eval is use to access different properties. Please help me as i m going right way but issue is in syntex. Thanks and regards
sasmi
You have got to mark the property as public to access it from the markup. Change the
"IsVisible"
property's access specifier to "public
" and your code will work. :) HTH! -
yes, it is right, are you facing any problem in this?
when i run this it giving error "DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'IsVisible'."
Sasmi
-
You have got to mark the property as public to access it from the markup. Change the
"IsVisible"
property's access specifier to "public
" and your code will work. :) HTH!I have change the property to public but still showing error "DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'IsVisible'."
Sasmi
-
I have change the property to public but still showing error "DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'IsVisible'."
Sasmi
Modify the gridview code where you set the visible property like this.
Visible='<%# IsVisible %>'
-
Modify the gridview code where you set the visible property like this.
Visible='<%# IsVisible %>'
Yes, Thanks now it working fine.... can i access any class property using this syntex? Thank you very much
Sasmi
-
Yes, Thanks now it working fine.... can i access any class property using this syntex? Thank you very much
Sasmi
hi! i've seen that you've solved your problem. but you can use also
<%=Server.HtmlEncode(IsVisible) %>
when you use IsVisible function to return a string :-D (parse true to "true" and false to "false") :laugh: