Showing posts with label datalist. Show all posts
Showing posts with label datalist. Show all posts

Thursday, March 29, 2012

pass parameter in hyperlink

Hi

I am displaying the results of a query in a datalist. There are 2 fields returned with one an icon set as a hyperlink as follows:

Smile [:)]
name

When someone clicks on the icon I would like the name parameter to be passed to a new page to be used in a new query. Can someone please point me in the right direction.

Matt

The simplest way of doing this is to append the name as a query string variable, e.g.

<a href="http://links.10026.com/?link=http://someurl.com?name=xyz">...</a>


Thanks for the quick response. My code looks as follows:

<ItemTemplate>

<asp:HyperLink ID="Hyperlink1" runat="server" NavigateUrl="~/Login.aspx"><asp:Image ID="Image1" runat="server" ImageUrl='<%# SetUrl(Eval("status")) %>' ImageAlign="Middle" /></asp:HyperLink><br />
<asp:Label ID="term_idLabel" runat="server" Text='<%# Eval("term_id") %>' Font-Names="Arial" Font-Size="Small" ForeColor="White"></asp:Label><br />
<br />
</ItemTemplate
Which displays my data as:

Smile [:)] Big Smile [:D]
name1 name2

If the user clicks on name1's icon I'd like to pass name1 as the parameter. How do I access this term_idLabel instance?
You'll want to change the NavigateUrl property in HyperLink1 so the term_id is evaluated and passed as a parameter. Try this:

NavigateUrl='<%# Eval("term_id", "~/Login.aspx?name={0}") %>'
The string will be formatted with the value for term_id replacing the {0}.

Pass Parameter to DataList Datasource!

Hi all,

I am trying pass a value to the DataSource method in a DataList like below.
DataSource = <%# GetData(DataBinder.Eval(Container.DataItem, "ID"))%>"

I get an error with this code, and am wondering if someone can show me the
correct syntax.

I have asked this question before, but unfortunately i don't remember the
correct syntax.

I know i can acheive the desired result using code behind 'ItemDataBound',
but am prefering to do it in the aspx page itself..

All help appreciated.

<asp:DataList ID="dlTest"
DataKeyField = "ID"
DataSource = <%# GetData(DataBinder.Eval(Container.DataItem,
"ID"))%>">
<ItemTemplate><%# DataBinder.Eval(Container.DataItem,
"Name")%></ItemTemplate>
</asp:DataList>

Cheers,
AdamDataSource should be set to an on object containing data items. What is it
in your case?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

"AJ" <AJ@.discussions.microsoft.comwrote in message
news:3C74BA0B-76DB-42B0-A32B-E2EF219A44BC@.microsoft.com...

Quote:

Originally Posted by

Hi all,
>
I am trying pass a value to the DataSource method in a DataList like
below.
DataSource = <%# GetData(DataBinder.Eval(Container.DataItem, "ID"))%>"
>
I get an error with this code, and am wondering if someone can show me the
correct syntax.
>
I have asked this question before, but unfortunately i don't remember the
correct syntax.
>
I know i can acheive the desired result using code behind 'ItemDataBound',
but am prefering to do it in the aspx page itself..
>
All help appreciated.
>
<asp:DataList ID="dlTest"
DataKeyField = "ID"
DataSource = <%# GetData(DataBinder.Eval(Container.DataItem,
"ID"))%>">
<ItemTemplate><%# DataBinder.Eval(Container.DataItem,
"Name")%></ItemTemplate>
</asp:DataList>
>
Cheers,
Adam

Saturday, March 24, 2012

Passing 2 Parameters from Datalist Control?

I have master/detail pages and pass a parameter from master page (datalist control) to detail page using session method.

Session.Add(

"prm_type", DataList1.SelectedValue);
Response.Redirect("detail.aspx");

The code, I had placed in the datalist "selectedindexchanged" method, above works well. In addition to this, I placed a textbox control in the datalist control to pass a second parameter to detail page. But i don't know how to reach that textbox value and pass the parameter to detail page within datalist selectedindexchanged method like above. I tried something like below, but i couldn't figure out.

Session.Add("prm_quantity", ? this must be my textbox control value);

How can i pass a second parameter like this?

Try with this:

TextBox tbText = (TextBox)DataList1.FindControl("TextBox1");
Session.Add("prm_quantity", tbText.Text);


I got an error message on this line:

Session.Add(

"prm_quantity", tbText.Text);

"NullReferenceException was unhandled by user code"
"Object reference not set to an instance of an object"


Hi,

It may be cache issue. Please look at this KB:

http://www.kbalertz.com/Feedback_831382.aspx

Good luck!