DataList control column

DataList control column

am 10.01.2008 19:37:40 von David C

I have a DataList control that displays file names from a directory. I
would like to conditionally add a string to the DataNavigateUrlFormatString
in a HyperlInk column before it is displayed. Where is the best place to do
that? Currently the DataNavigateUrlFormatString="ShowDocs.aspx?doc={0}" and
I want to sometimes add a 2nd querystring value. Thanks.

David

RE: DataList control column

am 10.01.2008 20:23:04 von pbromberg

DataList supports the ItemDataBound event, which is where you would do this
kind of "stuff":

void Item_Bound(Object sender, DataListItemEventArgs e)
{

if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{

// Retrieve the Label control in the current DataListItem.
Label PriceLabel = (Label)e.Item.FindControl("PriceLabel");
// modify the label, hyperlink, etc. here
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com


"David C" wrote:

> I have a DataList control that displays file names from a directory. I
> would like to conditionally add a string to the DataNavigateUrlFormatString
> in a HyperlInk column before it is displayed. Where is the best place to do
> that? Currently the DataNavigateUrlFormatString="ShowDocs.aspx?doc={0}" and
> I want to sometimes add a 2nd querystring value. Thanks.
>
> David
>
>
>

Re: DataList control column

am 10.01.2008 20:49:04 von David C

Thanks Peter. I have done things in RowDataBound in a GridView but never
anything with a DataList.

David
"Peter Bromberg [C# MVP]" wrote in message
news:A216BB3B-AF54-4FE3-A5DC-75E4E9C23CDE@microsoft.com...
> DataList supports the ItemDataBound event, which is where you would do
> this
> kind of "stuff":
>
> void Item_Bound(Object sender, DataListItemEventArgs e)
> {
>
> if (e.Item.ItemType == ListItemType.Item ||
> e.Item.ItemType == ListItemType.AlternatingItem)
> {
>
> // Retrieve the Label control in the current DataListItem.
> Label PriceLabel = (Label)e.Item.FindControl("PriceLabel");
> // modify the label, hyperlink, etc. here
> -- Peter
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> MetaFinder: http://www.blogmetafinder.com
>
>
> "David C" wrote:
>
>> I have a DataList control that displays file names from a directory. I
>> would like to conditionally add a string to the
>> DataNavigateUrlFormatString
>> in a HyperlInk column before it is displayed. Where is the best place to
>> do
>> that? Currently the DataNavigateUrlFormatString="ShowDocs.aspx?doc={0}"
>> and
>> I want to sometimes add a 2nd querystring value. Thanks.
>>
>> David
>>
>>
>>

Re: DataList control column

am 10.01.2008 21:08:24 von David C

Wait...there is no "ID" to use FindControl. It is a DataList and the column
is a HyperLink.

David
"Peter Bromberg [C# MVP]" wrote in message
news:A216BB3B-AF54-4FE3-A5DC-75E4E9C23CDE@microsoft.com...
> DataList supports the ItemDataBound event, which is where you would do
> this
> kind of "stuff":
>
> void Item_Bound(Object sender, DataListItemEventArgs e)
> {
>
> if (e.Item.ItemType == ListItemType.Item ||
> e.Item.ItemType == ListItemType.AlternatingItem)
> {
>
> // Retrieve the Label control in the current DataListItem.
> Label PriceLabel = (Label)e.Item.FindControl("PriceLabel");
> // modify the label, hyperlink, etc. here
> -- Peter
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> MetaFinder: http://www.blogmetafinder.com
>
>
> "David C" wrote:
>
>> I have a DataList control that displays file names from a directory. I
>> would like to conditionally add a string to the
>> DataNavigateUrlFormatString
>> in a HyperlInk column before it is displayed. Where is the best place to
>> do
>> that? Currently the DataNavigateUrlFormatString="ShowDocs.aspx?doc={0}"
>> and
>> I want to sometimes add a 2nd querystring value. Thanks.
>>
>> David
>>
>>
>>