Hi there, this is my question :
I would like to make te first page with a list coming from database (how to do?);
Ex <p><a "href:secondpage.aspx">Record text</a</p> etc. etc. and from this list choosing one of the record, using the id of the record, and open the second page where i can edit all the values of the record, do i need to do this with querystring? (and showing to the user the id of the record on the addressbar of IE)? or there is another way that allow me to open one record without showing data to the user?


Edited by grafic.web

3 Years
Discussion Span
Last Post by JorgeM

The easiest way is to integrate a gridview control and just attach that gridview to a data source all using the design view in Visual Studio.

Another option is to use a repeater control. This allows more flexibility on exactly what the output is going to look like.

and open the second page where i can edit all the values of the record, do i need to do this with querystring

Yes, that is one approach. very common. You pass the parameter via the query string. then on page2, you read the parameter, use that parameter in your database lookup and show the results for that parameter.

There are many other methods to doing this. For example, instead of using a generic <a> anchor element, you could use a hyperlink control. When the user clicks on it, you have this hyperlink control wired to a click event. store some parameter in a session variable. On the page2, look up the session variable to retreive the value.

Do you know how to connect to a datasource via controls and/or code behind?


Thanks for the fast answer!!

For : Do you know how to connect to a datasource via controls and/or code behind?
Not really... sorry... i just started learning this week..

Ho can i do a list of hyperlink control?

And.. i was thinkig that with session is to risky cause the user may woul edit many records and open many pages, and this woul mix everything.. no?

Sorry if i ask you, but can you post some code for me to understand?

Thanks again for your help!!



Start by adding a repeater control to your design view. on the right side, if you hover, you will be able to add a data source.. follow the wizard to connect to your dB, then table.

In the source view, it should look something like this... add the itemtemplate section by hand.

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

    <form id="form1" runat="server">
    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="Sql1">
            <a href="page2.aspx?id=<%# Eval("id") %>"><%# Eval("category") %></a><br />
        <asp:SqlDataSource ID="Sql1" runat="server" ConnectionString="<%$ ConnectionStrings:DB %>" SelectCommand="SELECT [id], [category] FROM [_table1]"></asp:SqlDataSource>

take a look at this code. hope it helps.

Edited by JorgeM


Let me see if i have a moment to provide a sample using a hyperlink control, not using the query string...

[edit] not using the querystring is a bit more elaborate than what i was originally thinking...

To not use a querystring, you'd need the form to submit (an autopostback) and you would have to capture the event, figure out what was clicked so that you can redirect the user to page2. There are other methods such as using client side methods to store something specific about what you clicked in a hidden input element, then read the value on the postback, but I'm not sure that its worth doing this work. [/edit]

Edited by JorgeM


thank again for your time!!!
This code is a very good example!!
If you got a moment to provide a sample using a hyperlink control.. will be great!!!



I wasnt thinking clearly when I suggested the hyperlink control. I should have suggested a linkbutton control instead. A link button renders as an <a> anchor element as well and gives you additional control.

So, still using the example above, within the <ItemTemplate> use a linkbutton control.

Here is an example.. I am writing this from the top of my head so you will need to validate its functionality..

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="Sql1">
    <asp:LinkButton runat="server" CommandArgument="<%# Eval("id") %>" OnCommand="lb_Command"><%# Eval("category") %></asp:LinkButton><br />

Here is a self standing example you can use to test and play with...

  <asp:LinkButton ID="lb1" runat="server" CommandArgument="1" OnCommand="lb_Command">CD</asp:LinkButton><br />
  <asp:LinkButton ID="lb2" runat="server" CommandArgument="2" OnCommand="lb_Command">DVD</asp:LinkButton><br />
  <asp:LinkButton ID="lb3" runat="server" CommandArgument="3" OnCommand="lb_Command">BOOK</asp:LinkButton> 

Here is the code behind that you will use to intercept the click of the link, store the value in a session, then redirect the user to page2.

protected void lb_Command(object sender, CommandEventArgs e)
   Session["order"] = e.CommandArgument;

Now on page2.aspx, within the page_load method, you simply need to read in the session variable, assign it to a local variable then do what ever operation you need to do and dispaly information back to the user.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.