Click here to Skip to main content
15,888,610 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: How to send the ID field of a datalist to another page? Pin
Christian Graus11-Mar-09 12:25
protectorChristian Graus11-Mar-09 12:25 
GeneralRe: How to send the ID field of a datalist to another page? Pin
Yusuf11-Mar-09 12:58
Yusuf11-Mar-09 12:58 
GeneralRe: How to send the ID field of a datalist to another page? Pin
Arroci11-Mar-09 13:19
Arroci11-Mar-09 13:19 
GeneralRe: How to send the ID field of a datalist to another page? Pin
Yusuf11-Mar-09 13:48
Yusuf11-Mar-09 13:48 
GeneralRe: How to send the ID field of a datalist to another page? Pin
Arroci11-Mar-09 14:15
Arroci11-Mar-09 14:15 
GeneralRe: How to send the ID field of a datalist to another page? Pin
Yusuf11-Mar-09 15:12
Yusuf11-Mar-09 15:12 
GeneralRe: How to send the ID field of a datalist to another page? Pin
Christian Graus11-Mar-09 15:46
protectorChristian Graus11-Mar-09 15:46 
GeneralRe: How to send the ID field of a datalist to another page? [modified] Pin
Arroci11-Mar-09 18:19
Arroci11-Mar-09 18:19 
Right so I got to work with your suggestions.

Yusuf:

Since I can only use Bind("ID") within a tag, i tried it under
Text='<%# Bind("ID") %>
and it just threw up the same null error. It just seems that it's not picking up the record's ID key because the button is nested in a template.

Christian

I got your suggestion to partially work. basically, it now posts to the next page, but it doesn't post the ID, instead it posts (interestingly):
http://localhost:2433/website/NewsArticle.aspx?ID=<%#Eval(\"ID\")%>


From the code:

<itemtemplate>
           ID:
           <asp:label id="IDLabel" runat="server" text="<%# Eval(" xmlns:asp="#unknown" />
           <asp:linkbutton id="GoToArticle" runat="server" postbackurl="~/NewsArticle.aspx?ID=<%#Eval(" xmlns:asp="#unknown">Go</asp:linkbutton>
      </itemtemplate>


So I think this is some headway. I'll also be looking up methods of posting query strings from inside an item template but I think all of us are starting to get there Big Grin | :-D .

I've been searching around and came across CommandArgument codes. They seem to be practicle for putting the <![CDATA[<%# Eval("ID") %>]]> in them. I'm currently looking at a way to use this in a query string. I had tried the following:

News.aspx
<asp:linkbutton id="GoToArticle" commandname="GoToArticle" xmlns:asp="#unknown">
      CommandArgument='<%#Container.DataItem, ("ID")%>' runat="server">Go</asp:linkbutton>


and the code-behind:
private void DataList1_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
 {
     {
         int ID = (int)e.CommandArgument;

         if (e.CommandName == "GoToArticle")
         {
             Response.Redirect("~/NewsArticle.aspx?ID=" + ID);
         }
     }
 }


Ironically, even though I'm getting the error:
No Overload Method 'ToString' takes '3' arguments


for line:

<asp:linkbutton id="GoToArticle" commandname="GoToArticle" xmlns:asp="#unknown">
CommandArgument='<%#Container.DataItem, ("ID")%>' runat="server">Go</asp:linkbutton>


I may have hit something good here. I just have to figure out how to stop the overload error! any help would be appriciated Big Grin | :-D .

UPDATE: Ah! Okey guys I've managed to get the query to post to the next page! The commandargument and commandname methods were correct. More importantly, I needed to add OnItemCommand to the datalist's ASP tag! If anyone requests source I would gladly post a generic copy Big Grin | :-D . I think after this I might actually post an article about implementing a button in a datalist to post ID values to another page, since it required a lot of cross referencing from google to get it done Big Grin | :-D .

Christian: big thank you for hinting the right direction by using the Eval to render the link button.

Yusuf: big thank you as well for directing me to posting values from one page to another using a query string.

and thank you both for aiding me through this. Now I need to get the generic page to display the article. I'm trying
<asp:label id="Label1" runat="server" xmlns:asp="#unknown"></asp:label>
with
protected void Page_Load(object sender, EventArgs e)
{
    this.Label1.Text = Request.QueryString["ArticleID"];

}


at the moment, but to no avail Frown | :(

modified on Thursday, March 12, 2009 10:33 AM

GeneralRe: How to send the ID field of a datalist to another page? Pin
Arroci12-Mar-09 10:26
Arroci12-Mar-09 10:26 
QuestionHow to display a jpg on a web page Pin
scjsb11-Mar-09 4:57
scjsb11-Mar-09 4:57 
AnswerRe: How to display a jpg on a web page Pin
Yusuf11-Mar-09 5:20
Yusuf11-Mar-09 5:20 
AnswerRe: How to display a jpg on a web page Pin
Rutvik Dave11-Mar-09 6:08
professionalRutvik Dave11-Mar-09 6:08 
AnswerRe: How to display a jpg on a web page Pin
Cybernate11-Mar-09 6:25
Cybernate11-Mar-09 6:25 
QuestionI need some direction on a web page Pin
Tom Wright11-Mar-09 4:36
Tom Wright11-Mar-09 4:36 
AnswerRe: I need some direction on a web page Pin
Yusuf11-Mar-09 5:22
Yusuf11-Mar-09 5:22 
GeneralRe: I need some direction on a web page Pin
Tom Wright11-Mar-09 6:04
Tom Wright11-Mar-09 6:04 
GeneralRe: I need some direction on a web page Pin
Cybernate11-Mar-09 6:26
Cybernate11-Mar-09 6:26 
GeneralRe: I need some direction on a web page Pin
Tom Wright11-Mar-09 11:16
Tom Wright11-Mar-09 11:16 
Questionsession state issues Pin
nerzhul8611-Mar-09 0:59
nerzhul8611-Mar-09 0:59 
AnswerRe: session state issues [modified] Pin
Rajeesh MP11-Mar-09 1:03
Rajeesh MP11-Mar-09 1:03 
GeneralRe: session state issues Pin
Cybernate11-Mar-09 6:32
Cybernate11-Mar-09 6:32 
QuestionRe: session state issues Pin
nerzhul8611-Mar-09 22:10
nerzhul8611-Mar-09 22:10 
QuestionAsynchronous pluggable protocols Pin
Rajeesh MP11-Mar-09 0:56
Rajeesh MP11-Mar-09 0:56 
QuestionPay Pal Integration Pin
Aman Bhullar11-Mar-09 0:40
Aman Bhullar11-Mar-09 0:40 
AnswerRe: Pay Pal Integration Pin
Rajeesh MP11-Mar-09 0:58
Rajeesh MP11-Mar-09 0:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.