Gridview, Checkbox and SQL Parameters based on LoginName
-
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 -
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" HeaderTeHi Alison, I think you can 'user' property of HttpContext Current request to get the info about currently logged in user . Check out this link
-
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
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>