Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Grid View DataBindings...

Grid View DataBindings...

Scheduled Pinned Locked Moved ASP.NET
designhelpcsharphtmlcss
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sasmi_Office
    wrote on last edited by
    #1

    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

    G L D 3 Replies Last reply
    0
    • S Sasmi_Office

      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

      G Offline
      G Offline
      Gaurav Dudeja India
      wrote on last edited by
      #2

      yes, it is right, are you facing any problem in this?

      S 1 Reply Last reply
      0
      • S Sasmi_Office

        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

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        why don't you set the visibiltiy to false in the method where you bind the grid? this is easier.

        1 Reply Last reply
        0
        • S Sasmi_Office

          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

          D Offline
          D Offline
          Dinesh Mani
          wrote on last edited by
          #4

          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!

          S 1 Reply Last reply
          0
          • G Gaurav Dudeja India

            yes, it is right, are you facing any problem in this?

            S Offline
            S Offline
            Sasmi_Office
            wrote on last edited by
            #5

            when i run this it giving error "DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'IsVisible'."

            Sasmi

            1 Reply Last reply
            0
            • D Dinesh Mani

              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!

              S Offline
              S Offline
              Sasmi_Office
              wrote on last edited by
              #6

              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

              D 1 Reply Last reply
              0
              • S Sasmi_Office

                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

                D Offline
                D Offline
                Dinesh Mani
                wrote on last edited by
                #7

                Modify the gridview code where you set the visible property like this. Visible='<%# IsVisible %>'

                S 1 Reply Last reply
                0
                • D Dinesh Mani

                  Modify the gridview code where you set the visible property like this. Visible='<%# IsVisible %>'

                  S Offline
                  S Offline
                  Sasmi_Office
                  wrote on last edited by
                  #8

                  Yes, Thanks now it working fine.... can i access any class property using this syntex? Thank you very much

                  Sasmi

                  P 1 Reply Last reply
                  0
                  • S Sasmi_Office

                    Yes, Thanks now it working fine.... can i access any class property using this syntex? Thank you very much

                    Sasmi

                    P Offline
                    P Offline
                    PunkIsNotDead
                    wrote on last edited by
                    #9

                    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:

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups