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
  1. Home
  2. Web Development
  3. ASP.NET
  4. Gridview, Checkbox and SQL Parameters based on LoginName

Gridview, Checkbox and SQL Parameters based on LoginName

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasecssasp-netvisual-studio
3 Posts 2 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.
  • A Offline
    A Offline
    ahayw01
    wrote on last edited by
    #1

    Hello, I am still learning ASP.NET, if you need additonal information or have questions please let me know. I am creating a ASP.NET site (C#) in Visual Studio.NET that is utlizing a grid view to pull data from a SQL DB. I am using the ASP.NET membership provider model for the website authentication. Access to the site is only allowed with the correct username and password. I have a webform call Document Checklist. The webform is connected to a SQL table called document_checklist. I need the Document Checklist webform to display only those documents that the logged in user has not approved. I need for the user to click on the checkbox for those documents that he has approved and click the submit button to update the SQL DB. The SQL DB contains the following columns user_name, document_name, document_url date_added, date_approved and checkbox. I have been trying to work throught this and am not certain how to proceed. 1. I am not certain how to query the SQL DB against my LoginName I have tried a few things, but am not able to capture the value of the LoginName and compare it to user_name value of teh SQL DB field. (The formatting of LoginName from ASP.NET and user_name from SQL DB is identical.) 2. I do not know how to utilze checkbox to update the SQL DB. 3. I do not know how to capture the date that the checkbox was checked and insert it into date_approved The code is below. I am not certain how to list the CheckBox_Changed in the code behind. Thank you in advance for your help. aspx C# code

    <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="document_checklist.aspx.cs" Inherits="members_document_checklist" Title="Untitled Page" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <h2>DOCUMENT CHECKLIST</h2>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
    <Columns>
    <asp:BoundField DataField="user_name" HeaderText="User Name" SortExpression="user_name" />
    <asp:TemplateField HeaderText="Document">
    <ItemTemplate>
    <asp:HyperLink ID="Document" NavigateUrl='<%# Eval("document_url") %>' Text='<%# Eval("document_name") %>' Target="_blank" runat="server" />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="document_type" HeaderTe

    N 1 Reply Last reply
    0
    • A ahayw01

      Hello, I am still learning ASP.NET, if you need additonal information or have questions please let me know. I am creating a ASP.NET site (C#) in Visual Studio.NET that is utlizing a grid view to pull data from a SQL DB. I am using the ASP.NET membership provider model for the website authentication. Access to the site is only allowed with the correct username and password. I have a webform call Document Checklist. The webform is connected to a SQL table called document_checklist. I need the Document Checklist webform to display only those documents that the logged in user has not approved. I need for the user to click on the checkbox for those documents that he has approved and click the submit button to update the SQL DB. The SQL DB contains the following columns user_name, document_name, document_url date_added, date_approved and checkbox. I have been trying to work throught this and am not certain how to proceed. 1. I am not certain how to query the SQL DB against my LoginName I have tried a few things, but am not able to capture the value of the LoginName and compare it to user_name value of teh SQL DB field. (The formatting of LoginName from ASP.NET and user_name from SQL DB is identical.) 2. I do not know how to utilze checkbox to update the SQL DB. 3. I do not know how to capture the date that the checkbox was checked and insert it into date_approved The code is below. I am not certain how to list the CheckBox_Changed in the code behind. Thank you in advance for your help. aspx C# code

      <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="document_checklist.aspx.cs" Inherits="members_document_checklist" Title="Untitled Page" %>
      <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

      <h2>DOCUMENT CHECKLIST</h2>
      <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
      <Columns>
      <asp:BoundField DataField="user_name" HeaderText="User Name" SortExpression="user_name" />
      <asp:TemplateField HeaderText="Document">
      <ItemTemplate>
      <asp:HyperLink ID="Document" NavigateUrl='<%# Eval("document_url") %>' Text='<%# Eval("document_name") %>' Target="_blank" runat="server" />
      </ItemTemplate>
      </asp:TemplateField>
      <asp:BoundField DataField="document_type" HeaderTe

      N Offline
      N Offline
      Nishant Singh
      wrote on last edited by
      #2

      Hi Alison, I think you can 'user' property of HttpContext Current request to get the info about currently logged in user . Check out this link

      A 1 Reply Last reply
      0
      • N Nishant Singh

        Hi Alison, I think you can 'user' property of HttpContext Current request to get the info about currently logged in user . Check out this link

        A Offline
        A Offline
        ahayw01
        wrote on last edited by
        #3

        Hello, Thank you for your response. I am not certain how I would use that to compare that value against the Username data field in SQL to only display values where loginname is equal to Username (in SQL). Below is my code for my aspx page. <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="document_checklist.aspx.cs" Inherits="document_checklist" Title="Document Checklist Report" %> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <h2>DOCUMENT CHECKLIST</h2> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField DataField="user_name" HeaderText="Username" SortExpression="user_name" /> <asp:BoundField DataField="document_name" HeaderText="Document" SortExpression="document_name" /> <asp:BoundField DataField="date_added" HeaderText="Date Added" SortExpression="date_added" /> <asp:TemplateField HeaderText="Document Read"> <ItemTemplate> </ItemTemplate> </asp:TemplateField> <asp:CheckBoxField DataField="checkbox" HeaderText="Document Read" SortExpression="checkbox" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:board_loginConnectionString3%>" SelectCommand="SELECT [user_name], [document_name], [document_type], [date_added], [checkbox] FROM [document_checklist] WHERE ([checkbox] = @checkbox)AND ([username] = @username)"> <SelectParameters> <asp:Parameter DefaultValue='0' Name="checkbox" Type="Byte" /> </SelectParameters> </asp:SqlDataSource> </asp:Content>

        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