Solved

GridVew Alternative

Posted on 2009-05-18
2
216 Views
Last Modified: 2012-05-07
Hi Everyone,

I am just getting in ASP.net having come from a PHP background in terms of web dev. One thing I did alot of in PHP was creating a table which was a list of Request i.e The Table consisted of a Name, Email and Edit Column. The information was pulled from the database and populated. The edit column was a link field which appended the Row ID to the URL and posted the user to this url.

At this URL i.e. www.mydomain.com?uid=134 the code would go away and look for entry 134 in the db (Using PK). And return the data so that it could be edited in a form.

I have been toying with the GridView, but I seem to have to break it to make it work basically, so I wondered if someone could suggest a solution, or point me to a tutorial which may do similar to what I want. I am not overly keen on the Databound stuff as most of the information is pulled directly from Classes. But I am open to having my mind changed if I can see advantages.

Any help / advice would be great.

Kind Regards

James Proctor
0
Comment
Question by:WJPS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
Kelevra earned 500 total points
ID: 24414369
Hi,

a few questions first:

In wich framework are you working in?

Do you know how to use the DOM in ASP.net and create your web controls from the server side?

There is an easy solution, that I personnaly use to do what you intend to do.

For a class that is the "recit" class, I have a collection of this strongly typed object, called Listerecits, that inherits from ArrayList.

and with a foreach loop, I create the elements of my table from the server side.

I even add a button, and on the click event of that button, I add an:
 new EventHandler(btnSelectioner_Click)
And because each buttons are unique, they get the ID (PK), of the table they come from, I can work further, and do, what I want on my button click event.

Here, I call, a function, that select, the selected element.
But,
you could do, an update, or delete all the same.

Hope this'll help!
Don't hesitate, if you have other questions!
//server side from here in C#:    
protected void Page_Load(object sender, EventArgs e)
    {
        //GateDiv.Visible = false;
        if (!IsPostBack)
        {
 
 
            ListeRecits listerecit = Controleur.RecupListeRecits(VarSession.StrUserId.ToString());
 
            VarSession.varlisterecit = listerecit;
        }
 
 
 
        foreach (Recit recit in VarSession.varlisterecit)
        {
            if (recit != null)
            {
 
                TableRow tr = new TableRow();
 
                TableCell tdTitre = new TableCell();
                TableCell tdPays = new TableCell();
                TableCell tdLieu = new TableCell();
                TableCell tdDate = new TableCell();
                TableCell tdBtn = new TableCell();
 
                Label lbltitre = new Label();
                lbltitre.Text = recit.titrerecit;
                Label lblpays = new Label();
                lblpays.Text = recit.pays.NomPays;
                Label lblLieu = new Label();
                lblLieu.Text = recit.lieurecit;
                Label lblDate = new Label();
                lblDate.Text = recit.daterecit.ToShortDateString();
 
                Button btnSelectioner = new Button();
                btnSelectioner.CssClass = "btnSelectionerCss";
                btnSelectioner.ID = recit.idrecit.ToString();
                btnSelectioner.Text = "Voir";
                btnSelectioner.Click += new EventHandler(btnSelectioner_Click);
 
                if (recit.ispartage  == 1)
                {
                    tr.BackColor = System.Drawing.Color.AntiqueWhite;
                    lbltitre.Text += " *!Partagé!*";
                }
 
 
                tdTitre.Controls.Add(lbltitre);
                tdPays.Controls.Add(lblpays);
                tdLieu.Controls.Add(lblLieu);
                tdDate.Controls.Add(lblDate);
                tdBtn.Controls.Add(btnSelectioner);
 
                tr.Controls.Add(tdTitre);
                tr.Controls.Add(tdPays);
                tr.Controls.Add(tdLieu);
                tr.Controls.Add(tdDate);
                tr.Controls.Add(tdBtn);
 
                this.TableMytracks.Controls.Add(tr);
 
 
            }
protected void btnSelectioner_Click(object sender, EventArgs args)
    {
        try
        {
            Button btn = (Button)sender;
            string idrecit = btn.ID;
            VarSession.idrecit = idrecit;
            Response.Redirect("~/1/ShowRecit.aspx");
        }
        catch (HttpException ex)
        { string error = ex.Message; }
 
    }
//Client side HERE:
 
 <asp:Table ID="TableMytracks" CssClass="TableMyTrackContents" runat="server">
                    </asp:Table>

Open in new window

0
 

Author Closing Comment

by:WJPS
ID: 31582636
Thanks for that, just what I was looking for, and a bit of re-asurance that not everyone used databound stuff.

Regards

James
0

Featured Post

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question