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
O

overtech06

@overtech06
About
Posts
8
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Need guidance for file upload
    O overtech06

    There are definitely options out there that will work with web handlers and webforms. I use a modified version of the blueimp file uploader on a couple of my webform applications. It supports drag and drop uploading, multiple files at a time, chunked uploads for large files, progress bars, etc. Do a search for "blueimp multiple file uploader" and check out the examples they have. Then if you have any specific questions I'll do the best I can to answer them. Dave

    Web Development question html asp-net architecture

  • How should I create a class that I can access across multiple ASP.NET pages?
    O overtech06

    You are correct, the data must be stored somewhere. I generally use a database, but any storage method would work. The idea in my example would be that CodeLayer.myProperties.myInt; would actually do the XML de-serialization in the property's get accessor. It just makes accessing those values very simple when you get to the page level... - Dave

    ASP.NET csharp question asp-net dotnet sysadmin

  • How should I create a class that I can access across multiple ASP.NET pages?
    O overtech06

    Create a class that inherits "System.UI.Web.Page" and put the properties there that you need to be able to access from all pages. Be sure to build your accessors there as well. All other pages in your web application should inherit from that class. Then the properties you built there will be accessible... Something like this:

    // Page class - myPage.cs
    Public class myPage : Page
    {
    protected SqlConnection conn;
    protected SqlCommand cmd;

    public myPage() : base()
    {
        string connectionString = ConfigurationManager.ConnectionString\["DBConnectionString"\].ConnectionString;
        this.conn = new SqlConnection(connectionString);
        this.cmd = new SqlCommand();
        this.cmd.Connection = conn;
    }
    
    protected int myIntProperty
    {
        // From here you can call your static classes
        get { return CodeLayer.myProperties.myInt; }
        set { CodeLayer.myProperties.myInt = value; }
    
    }
    

    }

    Now when you create a new page in your web application, your page should inherit this class. In this example that would mean that whenever the page loads, you would already have an SqlConnection and SqlCommand object defined and usable and you can access your "myInt" property.

    public partial class PageOne : myPage
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    // the SqlConnection and SqlCommand objects are already created
    cmd.CommandText = "SELECT * FROM myTable";
    this.myIntProperty = 10;
    }
    }

    - Dave

    ASP.NET csharp question asp-net dotnet sysadmin

  • gridview
    O overtech06

    Instead of binding the SQL command with the gridview, store the results of the SQL query that match your criteria in a dataset. Then bind the dataset with the gridview. I think this is what Abhishek was suggesting as well. It would look something like:

    // Create a dataset that represents the data you are retrieving from the database
    DataSet myDataSet = new DataSet();
    DataTable myDataTable = myDataTable.Tables.Add();
    myDataTable.Columns.Add("ID", typeof(int));
    myDataTable.Columns.Add("Foo", typeof(string));
    myDataTable.Columns.Add("Bar", typeof(string));

    // Execute your sql reader as normal
    connection.Open();
    SqlDataReader dr = cmd.ExecuteReader();
    while(dr.Read())
    {
    // instead of binding the reader, add the records you want to the dataset
    if (dr["myCriteria"].ToString() == "this")
    {
    myDataTable.Rows.Add(
    (int)dr["ID"],
    dr["Foo"].ToString(),
    dr["Bar"].ToString()
    );
    }
    }
    dr.Close();
    connection.Close();

    // Now bind the dataset you created to your GridView
    myGridView.DataSource = myDataSet;
    myGridView.BindData();

    This could be done more elegantly by using myDataTable.Load(dr) then removing the rows that do not meet your criteria via a LINQ statement. But it should give you an idea of what you are trying to accomplish with a DataSet and get you started... - Dave

    ASP.NET tutorial question

  • Binding Controls via Generic Method
    O overtech06

    That's what I've already done in my current solution. I was just looking for a common interface that would allow me to cover them all in one Generic method... - Dave

    ASP.NET help css database wpf wcf

  • Binding Controls via Generic Method
    O overtech06

    I think that might be a little outside of my comfort zone, but I'll do some research on it. It might be a good learning experience if nothing else... I was really hoping there would be some base class that I had just overlooked that would be inclusive of all three control types... - Dave

    ASP.NET help css database wpf wcf

  • Binding Controls via Generic Method
    O overtech06

    I have a few web applications that I maintain and I find myself very often writing the same block of code over and over again to bind a GridView to a data source. I'm trying to create a Generic method to handle data binding but I'm having trouble getting it to work with Repeaters and DataLists. Here is the Generic method I have so far:

        public void BindControl<T>(T control, SqlCommand sql) where T : System.Web.UI.WebControls.BaseDataBoundControl
        {
            cmd = sql;
            cn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                control.DataSource = dr;
                control.DataBind();
            }
            dr.Close();
            cn.Close();
        }
    

    That way I can just define my CommandText then make a call to "BindControls(myGridView, cmd)" instead of retyping this same basic block of code every time I need to bind a grid. The problem is, this doesn't work with Repeaters or DataLists. The error shown says "There is no implicit reference conversion from 'System.Web.UI.WebControls.Repeater' to 'System.Web.UI.WebControls.BaseDataBoundControl'." I can't seem to find the right base class that is in common with all 3 controls. For now I have overloaded the method specifically for Repeaters and DataLists, but does anyone know what I could use instead of "BaseDataBoundControl" that would work for all three control types? - Dave

    ASP.NET help css database wpf wcf

  • gridview
    O overtech06

    Normally you would build that condition into your SQL query statement so that the query only returns those rows you want included in the gridview. - Dave

    ASP.NET tutorial question
  • Login

  • Don't have an account? Register

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