Converting a gridView using an Sql Datasource to a gridview who is not using an SQL DataSource

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
tompy_nation
2/13/2008 11:36:24 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

1 Replies
1850 Views

Similar Articles

[PageSpeed] 17

forget this question... problem is solved


Don't forget to click "Mark as Answer" on the post that helped you.
0
tompy_nation
2/13/2008 2:58:53 PM
Reply:

Similar Artilces:

How to change the SQL used for the GridView, when using a control parameter in the datasource
I'm using a GridVeiw with and Access database. I want to allow users to select a date and then update the GridView to show only data entered after that date. So my question is, how do I modify the SQL used by the datagrid? I'm using a control parameter as part of my AccessDataSource and I think that is what I'm having trouble figuring out how to include. Here is my datasource, with the control parameter in the the GridView. The GridView works fine with these initial settings settings. <asp:AccessDataSource ID="AccessDataSourceForwView" runat="server" ConflictDetection="Compa...

code for Custom paging without using sqldatasource control and sql datasource control for gridview...........
 code for Custom paging without using sqldatasource control and sql datasource control for gridview...........i need code for how to show all pagenumbers in gridview with custom paging in gridview..............It is very urgent................................. T.Ashok Kumar  suppose that we have a table like thisCountryId  identity intCountryTitle    nvarchar(50)you can use this sql command for paging the dataUSE [CyberOffice]GO/****** Object:  StoredProcedure [dbo].[CountryGetListPaged]    Script Date: 09/17/2008 14:01:06 ******/SET A...

Gridview Filter using Dropdown where dropdown is populated from a distinct list in the Gridview
I have a report page that shows the user who accessed pages, when they accessed it, and the page they accessed.  I have it attached to some dates, so they can easily filter the search down.  What I want to do is to further filter the list with a dropdown of users, so they can see which user viewed what pages over a certain time frame.  I know how to query the database for a list of users and then populate the dropdown with all the users...then attach that dropdown to the sqldatasource for the gridview to filter it down by user.   But, what if I just want to popu...

Trying to use the FAQ " Sorting and paging in the GridView control when not using data source controls "Sorting and paging in the GridView control when not using..."
and I am not getting the results I had hoped for.  I keep getting a "Compiler Error Message: CS0123: No overload for 'AdhocJobGridView_PageIndexChanged' matches delegate 'System.EventHandler'".   Here is my event handling... protected void AdhocJobGridView_PageIndexChanged(object sender, GridViewPageEventArgs e){ try { AdhocJobGridView.DataSource = wsBaseInfoArray; AdhocJobGridView.PageIndex = e.NewPageIndex; AdhocJobGridView.DataBind(); }catch (Exception ex) {throw ex; }   Here is my aspx... <asp:GridView ID="AdhocJobGridView...

Cannot use same sql datasource for formview
Hello, I have problem that is confusing me... I am using a gridview on page1 that when selected navigates to page2 queried by the ID. On page2 i have a gridview which uses a sqldatasource using the query parameter of the ID taken from Page1. I have this working, but when i try to replace the gridview with a formview (with the same sqldatasource) i get the following error: 'System.Data.DataRowView' does not contain a property with the name 'publicationID' Why can i not use the same sqldatasource in the formview??  Kind regards, Hi, Where you getting that error? Can...

Binding GridView without using an SQL datasource
I am currently working on porting a solid VB6 app to ASP 2.0 (yeah a big jump). The app has a tier structure and is heavly dependent on the business layer. Due to that i cannot use simple ASP direct Databinding and need to use binding to datasets. I have started experimenting to get some traction and I cannot get the simplest example to work !! here is some test code. Here is what happens that is very puzzling to me. Upon hitting "edit" the event gets fired and the browser displays a blank page. I even tried to persist the DataSet object as a private class variable but that became...

Problem using two gridviews when using selected value of 1st to control datasource of 2nd
 I have a page with 2 gridviews. When you select a row in the first gridview, the DataKey of that row gets passed to the second gridview, which then displays a list of related records. I've read at http://www.asp.net/learn/data-access/tutorial-08-cs.aspx that there can be issues around page lifecycle timing that can affect what I'm doing so I've tried to follow the instructions there. However, I'm still having problems.Here's the flow of what I want to happen:a) User clicks row in gridview1.b) Postback occurs.c) gridview1 is selected, gridview2 shows records relating...

How to: 2.0 Encrypting Field Data Using a Formview Control and a Gridview control for SQL
The Exercise: Using a Formview Control and a Gridview control to Encrypt data going into SQL, Decrypt it for display, and Be able to Edit it. Using Visual Studio 2005 ASP.NET 2.0 Framework   Files needed: – QSEnc64.vb to be placed in the App_Code folder of your application TestInsertEdit.aspx in the root of the application TestInsertEdit.aspx.vb in the root of the application A Web Config file with a valid ConnectionString Your_SQLConnectionString A SQL Database that you can add the test table to (see script below)   Hopefully this exercise will save you the time it to...

GridView RowCreated event when using ObjectDataSource...GridView.DataSource is Null...
I have used the RowCreated event in the past to create grouping in a standard GridView without issues. However, in all of these cases the DataSource I used for each GridView had always been a DataTable. When I use the same code against a GridView that has its DataSource as an ObjectDataSource (the ODS returns a DataTable) the code fails because the GridView.DataSource is NULL. Is this expected behaviour for a GridView that is attached to an ObjectDataSource or is there another way to access the original DataSource of a GridView in the RowCreated event? DataTable example that has worked in th...

5 datasource using one gridview control
Hi: I have a dropdown list, according to user select different item value, such as: male, female, country... then showing the gridview. At the moment, I have 5 gridviews (all have same coloums and format from one table) to show the result (infact using hide and show panels), I feel that is not good way, too many gridviews! I am think using one gridview to show the result according to which item is selected. I feel hard to handle this because it needs binding the datasauce dynamically. How to set the DataSourceID dynamically? it can save a lot of lines of auto generated code...

Using a custom SQL statement in a gridview control
I have used a custom SQL statement to display data on an aspx page using a gridview control. The problem I am having is that when I test the SQL using "configure data source" inside Visual Web Developer, I do get results. But when I display my web page in a browser, I don't get any results. My gridview control is pulling back results based on the session. I have tried only adding one item to the session and leaving everything else blank to see if I get results, but I don't. Can you take a look at this SQL statement and see if you think I did anything wrong? SELECT D...

Not able to use sql Convert function in gridview
 Hi!Im trying to get europe time in one of my gridviews (instead of am/pm format), and tryed using following select-string:SelectCommand="SELECT Convert(DateTime, vagt.start, 13), vagt.***, medarbejder.fornavn + ' ' + medarbejder.efternavn AS Expr1, medarbejder.medarbejder_id, vagt.vagt_id FROM vagt INNER JOIN medarbejder ON vagt.medarbejder_id = medarbejder.medarbejder_id WHERE vagt.dags_id = @intDagsid" The thing to note ofc, is the Convert() part. Now, when i use that method on the "vagt.start" column, it gives me an error stating it cant fint a field...

Using Gridview for delete, update and select using seperate sql statements and parameters
Hi everyone, I have a gridview which is bound to a sqldatasource which runs a stored procedure using userid as a parameter.  This then puts into a gridview all the surveys that that user has created. This all work fine, the problem is that when I put a delete button on the grid it expects the same parameter that the select statement uses which is the userid.  However the stored procedure which deletes from the database uses surveyID as the parameter as i need the user to be able to choose which survey they want to delete. My question is how do you have a delete button which ru...

SQL Datasource And GridView
Ok here is the situation I have a field on my form called aspnet_currentuser which I populate in the load event like the following: Then in the sqldatasource control (code below) I attempt to populate the grid using that param and one other however the gridview returns no result. Please assist and thanks. Dim currentusername As String Dim uid As String If (User.Identity.IsAuthenticated) Then currentusername = Membership.GetUser().ToString() uid = Membership.GetUser(currentusername).ProviderUserKey.ToString() aspnet_currentuser.Text = Membership.GetUser(currentusername).ProviderUserKe...

Web resources about - Converting a gridView using an Sql Datasource to a gridview who is not using an SQL DataSource - asp.net.presentation-controls

Facebook Begins Converting Users To HTTPS
Are you willing to sacrifice a little bit of speed for a lot more safety? Facebook is asking that very question with its announcement that it ...

Facebook No Longer Converting Groups Into Pages
Back when Facebook first launched Facebook Pages, many businesses and brands who had built up substantial audiences in their Facebook Groups ...

Vert - simply converting for iPhone, iPad, and iPod touch on the iTunes App Store
Get Vert - simply converting on the App Store. See screenshots and ratings, and read customer reviews.

Converting SIM Card to Micro SIM Card - Flickr - Photo Sharing!
Place new Micro SIM into the iPhone SIM card tray

Ayaan Hirsi Ali on Converting Muslims to Christianity - YouTube
Complete video at: http://fora.tv/2010/07/29/Nomad_From_Islam_to_America_with_Ayaan_Hirsi_Ali Ayaan Hirsi Ali explains her support of missionary ...

Click go fears of converting print files
Is there a way to convert a print queue item to a .RTF or .PDF file? I like to save or email them. - The Sydney Morning Herald

Sudanese woman ordered to hang under sharia law for converting to Christianity gives birth
Khartoum, Sudan: A Christian Sudanese woman sentenced to hang for apostasy has given birth in jail, a Western diplomat said on Tuesday.

Imams warn against radicalism to Aboriginal inmates converting to Islam
The prison system has enlisted the help of ASIO to crack down on radicalisation behind bars amid revelations that Aboriginals are converting ...

Converting the world's companies one by one - The Science Show - ABC Radio National (Australian Broadcasting ...
Image: Trucks carrying logs make their way up a road in Jambi, Indonesia. A vast area of the Sumatran forest, and orangutan habitat, is being ...

Converting Churches Into Homes Is The Latest Hollywood Trend
You don't have to be a believer to be moved by the beauty of a church.

Resources last updated: 12/7/2015 8:30:34 AM