How can i rewrite this page so that i doesnt make use of an SqlDataSource?
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="LoginHistory.ascx.cs" Inherits="Private_UserControls_WebUserControl" %> <html> <head> <%--<link rel="stylesheet" href="BaldwinPortal.css" mce_href="BaldwinPortal.css" type="text/css" />--%> <title>Login History</title> </head> <body style="margin:0 0 0 0;padding:0 0 0 0"> <asp:ScriptManager ID="scriptMan" runat="server" SupportsPartialRendering="False"></asp:ScriptManager> <asp:Panel ID="pnlLoginHistory" DefaultButton="btnZoek" runat="server" Width="650px" meta:resourcekey="pnlLoginHistoryResource1"> <table cellpadding="0" cellspacing="0" style="width: 650px" > <tr><td style="valign:top; height: 68px; width: 650px;" valign="top"> <table cellpadding="0" cellspacing="0" style="height: 64px"> <tr valign="top"> <td style="height: 28px" > <asp:Label ID="lblUsername" runat="server" Text="User name:" Width="90px" Font-Names="Trebuchet MS" Font-Size="10pt" meta:resourcekey="lblUsernameResource1"></asp:Label></td> <td style="height: 28px"><asp:TextBox ID="txtUserName" runat="server" Width="162px" meta:resourcekey="txtUserNameResource1"></asp:TextBox> </td> <td style="height: 28px"> <asp:Label ID="lblDataRange" runat="server" Text="Data Range:" Width="84px" Font-Names="Trebuchet MS" Font-Size="10pt" meta:resourcekey="lblDataRangeResource1"></asp:Label></td> <td rowspan="2" style="height: 28px; width: 277px;"> <table> <tr> <td>Start: <asp:TextBox ID="txtStart" runat="server" meta:resourcekey="txtStartResource1"></asp:TextBox> <a href="javascript:GetDateNow('');");"><img alt="Calendar" height="16" src="../../Data/Commands/cal.gif" width="16" style="border:0" /></a><ajax:MaskedEditExtender ID="MaskedEditExtender" runat="server" MaskType="Date" Mask="99/99/9999" UserDateFormat="DayMonthYear" CultureName="nl-BE" TargetControlID="txtStart" CultureAMPMPlaceholder="" CultureCurrencySymbolPlaceholder="€" CultureDateFormat="DMY" CultureDatePlaceholder="/" CultureDecimalPlaceholder="," CultureThousandsPlaceholder="." CultureTimePlaceholder=":" Enabled="True"></ajax:MaskedEditExtender> </td> </tr> <tr> <td>End: <asp:TextBox ID="txtEnd" runat="server" meta:resourcekey="txtEndResource1"></asp:TextBox> <a href="javascript:GetDateNow('');"><img alt="Calendar" height="16" src="../../Data/Commands/cal.gif" width="16" style="border:0" /></a><ajax:MaskedEditExtender ID="MaskedEditExtender1" runat="server" MaskType="Date" Mask="99/99/9999" UserDateFormat="DayMonthYear" CultureName="nl-BE" TargetControlID="txtEnd" CultureAMPMPlaceholder="" CultureCurrencySymbolPlaceholder="€" CultureDateFormat="DMY" CultureDatePlaceholder="/" CultureDecimalPlaceholder="," CultureThousandsPlaceholder="." CultureTimePlaceholder=":" Enabled="True"></ajax:MaskedEditExtender> </td> </tr> </table> </td> </tr> <tr></tr> </table> <asp:Button ID="btnZoek" CssClass="button" runat="server" Text="Zoek" Width="17%" Height="25px" OnClick="btnZoek_Click" ValidationGroup="val_SearchHistory" meta:resourcekey="btnZoekResource1"/> <asp:Button ID="btnHerstel" CssClass="button" runat="server" Text="Herstel" Width="16%" Height="25px" OnClick="btnHerstel_Click" ValidationGroup="val_SearchHistory" meta:resourcekey="btnHerstelResource1"/></td><td valign="top" style="height: 68px; width: 1px;"> <br /> </td></tr> <tr><td colspan="2" valign="top"> <br /> <asp:GridView ID="gridLoginHistory" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" BorderStyle="None" BorderWidth="0px" CellPadding="3" CssClass="GridNormal" DataSourceID="sqlLoginHistory" GridLines="None" PageSize="15" Width="100%" OnRowDataBound="gridLoginHistory_RowDataBound" OnPageIndexChanged="gridLoginHistory_PageIndexChanged" OnPageIndexChanging="gridLoginHistory_PageIndexChanging" meta:resourcekey="gridLoginHistoryResource1"> <Columns> <asp:BoundField HeaderText="Nr." ReadOnly="True" meta:resourcekey="BoundFieldResource1"> <ItemStyle HorizontalAlign="Right" Width="1%" /> </asp:BoundField> <asp:BoundField HeaderText="User Number" DataField="Username" ReadOnly="True" meta:resourcekey="BoundFieldResource2" /> <asp:BoundField HeaderText="Session ID" DataField="SessionID" ReadOnly="True" meta:resourcekey="BoundFieldResource3" /> <asp:BoundField HeaderText="Login Time" DataField="LoginTime" ReadOnly="True" meta:resourcekey="BoundFieldResource4" /> </Columns> <EmptyDataTemplate><table cellpadding="0" cellspacing="0" width="100%" id="tblEmptyDataStyle"><tr><td><asp:Label ID="lblEmptyData" runat="server" Text="There is no login history available" meta:resourcekey="lblEmptyDataResource1"></asp:Label></td></tr></table></EmptyDataTemplate> <HeaderStyle CssClass="GridHeaderNormal" HorizontalAlign="Left" /> <RowStyle CssClass="GridRowNormal" /> <FooterStyle CssClass="GridFooterNormal" /> <PagerStyle CssClass="GridFooterNormal" ForeColor="#FF9900" /> </asp:GridView> </td></tr></table> </asp:Panel> <asp:SqlDataSource ID="sqlLoginHistory" runat="server" OnSelecting="sqlLoginHistory_Selecting"></asp:SqlDataSource> </body> </html>With following code behind:using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using be.esc.baldwin; public partial class Private_UserControls_WebUserControl : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { try { Gebruiker huidig = (Gebruiker)Session["Gebruiker"]; if (!huidig.Admin) { Response.Redirect("ErrorPages/noaccess.html"); } } catch { Server.Transfer("login.aspx"); } { txtUserName.Focus(); if (!Page.IsPostBack) { pnlLoginHistory.Visible = true; } buildGrid(); } } public void buildGrid() { sqlLoginHistory.ConnectionString = @"Data Source=PC0001\NAVSERVER;Initial Catalog=xxx;User ID=xxx;Password=xxx"; sqlLoginHistory.ProviderName = "System.Data.SqlClient"; sqlLoginHistory.SelectParameters.Clear(); sqlLoginHistory.SelectCommandType = SqlDataSourceCommandType.StoredProcedure; sqlLoginHistory.SelectCommand = "log_SelectAll"; sqlLoginHistory.SelectParameters.Add(new Parameter("UserName", TypeCode.String, "%")); sqlLoginHistory.SelectParameters.Add(new Parameter("DateStart", TypeCode.DateTime, "01/01/2000")); sqlLoginHistory.SelectParameters.Add(new Parameter("DateEnd", TypeCode.DateTime, "31/12/2050")); } protected void btnZoek_Click(object sender, EventArgs e) { gridLoginHistory.PageIndex = 0; applyFilter(); } public void applyFilter() { sqlLoginHistory.ConnectionString = sqlLoginHistory.ProviderName = "System.Data.SqlClient"; sqlLoginHistory.SelectParameters["UserName"].DefaultValue = (txtUserName.Text.Length == 0 ? "%" : txtUserName.Text); sqlLoginHistory.SelectParameters["DateStart"].DefaultValue = (txtStart.Text.Length == 0 ? "01/01/2000" : txtStart.Text); sqlLoginHistory.SelectParameters["DateEnd"].DefaultValue = (txtEnd.Text.Length == 0 ? "31/12/2050" : txtEnd.Text); } protected void btnHerstel_Click(object sender, EventArgs e) { sqlLoginHistory.ConnectionString =sqlLoginHistory.ProviderName = "System.Data.SqlClient"; sqlLoginHistory.SelectParameters["UserName"].DefaultValue = "%"; sqlLoginHistory.SelectParameters["DateStart"].DefaultValue = "01/01/2000"; sqlLoginHistory.SelectParameters["DateEnd"].DefaultValue = "31/12/2050"; txtUserName.Text = ""; txtEnd.Text = ""; txtStart.Text = ""; gridLoginHistory.DataBind(); } protected void gridLoginHistory_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType.Equals(DataControlRowType.DataRow)) { e.Row.Cells[0].Text = "" + ((((GridView)sender).PageIndex * ((GridView)sender).PageSize) + (e.Row.RowIndex + 1)); } } protected void gridLoginHistory_PageIndexChanging(object sender, GridViewPageEventArgs e) { } protected void gridLoginHistory_PageIndexChanged(object sender, EventArgs e) { applyFilter(); } protected void sqlLoginHistory_Selecting(object sender, SqlDataSourceSelectingEventArgs e) { e.Command.CommandTimeout = 1000; } }
Don't forget to click "Mark as Answer" on the post that helped you.
![]() |
0 |
![]() |
forget this question... problem is solved
Don't forget to click "Mark as Answer" on the post that helped you.
![]() |
0 |
![]() |