Connecting Tech Pros Worldwide Forums | Help | Site Map

Need help with hiding LinkButton in DataList

News
Guest
 
Posts: n/a
#1: Nov 18 '05
Hi,

I need help with datalist and linkbutton. I need a LinkButton to display in
datalist if datafield "is_measure_customchecklist" in a db table set to
true.

Here is the code (in parts):

<asp:DataList id="dtl1"
runat="server"
DataKeyField="program_id"
OnItemCommand="DoItemSelect"
OnItemCreated="Item_Created"
OnItemDataBound="BindProgramGrid" >


<ItemTemplate>
<%# Container.DataItem("name") %> &nbsp;
<asp:LinkButton Visible="false" ID="managechecklist"
CommandName="managechecklist" Text="Manage Checklist" CommandArgument='<%#
DataBinder.Eval(Container.DataItem, "is_measure_customchecklist") %>'
Runat="server" />
</ItemTemplate>

<SelectedItemTemplate>
<b><%# Container.DataItem("name") %></b> &nbsp; <asp:LinkButton
CommandName="Editprogram" Text="Edit Program" runat="server" /> &nbsp;
<asp:LinkButton ID="managechecklist" CommandName="managechecklist"
Text="Manage Checklist" CommandArgument='<%#
DataBinder.Eval(Container.DataItem, "is_measure_customchecklist") %>'
Runat="server" />
.....
</SelectedItemTemplate>


1. I tried with this method but can not get commandargument (understand that
commandargument is not part of DataListItemEventArgs):

Sub Item_Created(sender As Object, e As DataListItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
' Retrieve the Label control in the current DataListItem.
Dim lbtnManageCheckist As LinkButton =
CType(e.Item.FindControl("managechecklist"), LinkButton)

lbtnManageCheckist.visible = False
If lbtnManageCheckist.CommandArgument.toString() Then
lbtnManageCheckist.visible = True
End If

End If
End Sub


2. I tried another way, here I can get to command argument value but setting
of the link button to visible is not working:

Sub DoItemSelect(sender As Object, e As DataListCommandEventArgs)

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
' Retrieve the Label control in the current DataListItem.
Dim lbtnManageCheckist As LinkButton =
CType(e.Item.FindControl("managechecklist"), LinkButton)

lbtnManageCheckist.visible = False
If lbtnManageCheckist.CommandArgument.toString() Then
lbtnManageCheckist.visible = True
End If

End If
End Sub




Can anyone advise what is the better way to get this thing working. I need
link button to appear in DataList on condition "is_measure_customchecklist"
is true


Thank you...



Wardeaux
Guest
 
Posts: n/a
#2: Nov 18 '05

re: Need help with hiding LinkButton in DataList


In #2 you wrote:

If lbtnManageCheckist.CommandArgument.toString() Then
lbtnManageCheckist.visible = True
End If

try using:
If lbtnManageCheckist.CommandArgument.toString() = "True" Then ....

the .toString() method will evaluate to Boolean True if is returns anything,
I believe you are looking for the text string "True" since you are using the
toString() to convert the CommandArgument contents to a text string...

Hope this helps! :)
wardeaux



"News" <gena@mailcity.com> wrote in message
news:bfednf15vOvJuHHdRVn-jA@magma.ca...[color=blue]
> Hi,
>
> I need help with datalist and linkbutton. I need a LinkButton to display[/color]
in[color=blue]
> datalist if datafield "is_measure_customchecklist" in a db table set to
> true.
>
> Here is the code (in parts):
>
> <asp:DataList id="dtl1"
> runat="server"
> DataKeyField="program_id"
> OnItemCommand="DoItemSelect"
> OnItemCreated="Item_Created"
> OnItemDataBound="BindProgramGrid" >
>
>
> <ItemTemplate>
> <%# Container.DataItem("name") %> &nbsp;
> <asp:LinkButton Visible="false" ID="managechecklist"
> CommandName="managechecklist" Text="Manage Checklist" CommandArgument='<%#
> DataBinder.Eval(Container.DataItem, "is_measure_customchecklist") %>'
> Runat="server" />
> </ItemTemplate>
>
> <SelectedItemTemplate>
> <b><%# Container.DataItem("name") %></b> &nbsp; <asp:LinkButton
> CommandName="Editprogram" Text="Edit Program" runat="server" /> &nbsp;
> <asp:LinkButton ID="managechecklist" CommandName="managechecklist"
> Text="Manage Checklist" CommandArgument='<%#
> DataBinder.Eval(Container.DataItem, "is_measure_customchecklist") %>'
> Runat="server" />
> ....
> </SelectedItemTemplate>
>
>
> 1. I tried with this method but can not get commandargument (understand[/color]
that[color=blue]
> commandargument is not part of DataListItemEventArgs):
>
> Sub Item_Created(sender As Object, e As DataListItemEventArgs)
> If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
> ListItemType.AlternatingItem Then
> ' Retrieve the Label control in the current DataListItem.
> Dim lbtnManageCheckist As LinkButton =
> CType(e.Item.FindControl("managechecklist"), LinkButton)
>
> lbtnManageCheckist.visible = False
> If lbtnManageCheckist.CommandArgument.toString() Then
> lbtnManageCheckist.visible = True
> End If
>
> End If
> End Sub
>
>
> 2. I tried another way, here I can get to command argument value but[/color]
setting[color=blue]
> of the link button to visible is not working:
>
> Sub DoItemSelect(sender As Object, e As DataListCommandEventArgs)
>
> If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
> ListItemType.AlternatingItem Then
> ' Retrieve the Label control in the current DataListItem.
> Dim lbtnManageCheckist As LinkButton =
> CType(e.Item.FindControl("managechecklist"), LinkButton)
>
> lbtnManageCheckist.visible = False
> If lbtnManageCheckist.CommandArgument.toString() Then
> lbtnManageCheckist.visible = True
> End If
>
> End If
> End Sub
>
>
>
>
> Can anyone advise what is the better way to get this thing working. I need
> link button to appear in DataList on condition[/color]
"is_measure_customchecklist"[color=blue]
> is true
>
>
> Thank you...
>
>[/color]


News
Guest
 
Posts: n/a
#3: Nov 18 '05

re: Need help with hiding LinkButton in DataList


Problem is, in the #2 it does not matter if it is True or "True" as I can
set the control visibility in that Sub, in the #2 method I can not get the
value of the CommandArgument which has the value of db field
"is_measure_customchecklist". I can get this value in #1, where I can not
set the visiblity of the LinkButton...



"Wardeaux" <wardeaux@bellsouth.net> wrote in message
news:umebOMEZEHA.2216@TK2MSFTNGP10.phx.gbl...[color=blue]
> In #2 you wrote:
>
> If lbtnManageCheckist.CommandArgument.toString() Then
> lbtnManageCheckist.visible = True
> End If
>
> try using:
> If lbtnManageCheckist.CommandArgument.toString() = "True" Then ....
>
> the .toString() method will evaluate to Boolean True if is returns[/color]
anything,[color=blue]
> I believe you are looking for the text string "True" since you are using[/color]
the[color=blue]
> toString() to convert the CommandArgument contents to a text string...
>
> Hope this helps! :)
> wardeaux
>
>
>
> "News" <gena@mailcity.com> wrote in message
> news:bfednf15vOvJuHHdRVn-jA@magma.ca...[color=green]
> > Hi,
> >
> > I need help with datalist and linkbutton. I need a LinkButton to display[/color]
> in[color=green]
> > datalist if datafield "is_measure_customchecklist" in a db table set to
> > true.
> >
> > Here is the code (in parts):
> >
> > <asp:DataList id="dtl1"
> > runat="server"
> > DataKeyField="program_id"
> > OnItemCommand="DoItemSelect"
> > OnItemCreated="Item_Created"
> > OnItemDataBound="BindProgramGrid" >
> >
> >
> > <ItemTemplate>
> > <%# Container.DataItem("name") %> &nbsp;
> > <asp:LinkButton Visible="false" ID="managechecklist"
> > CommandName="managechecklist" Text="Manage Checklist"[/color][/color]
CommandArgument='<%#[color=blue][color=green]
> > DataBinder.Eval(Container.DataItem, "is_measure_customchecklist") %>'
> > Runat="server" />
> > </ItemTemplate>
> >
> > <SelectedItemTemplate>
> > <b><%# Container.DataItem("name") %></b> &nbsp; <asp:LinkButton
> > CommandName="Editprogram" Text="Edit Program" runat="server" /> &nbsp;
> > <asp:LinkButton ID="managechecklist" CommandName="managechecklist"
> > Text="Manage Checklist" CommandArgument='<%#
> > DataBinder.Eval(Container.DataItem, "is_measure_customchecklist") %>'
> > Runat="server" />
> > ....
> > </SelectedItemTemplate>
> >
> >
> > 1. I tried with this method but can not get commandargument (understand[/color]
> that[color=green]
> > commandargument is not part of DataListItemEventArgs):
> >
> > Sub Item_Created(sender As Object, e As DataListItemEventArgs)
> > If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
> > ListItemType.AlternatingItem Then
> > ' Retrieve the Label control in the current DataListItem.
> > Dim lbtnManageCheckist As LinkButton =
> > CType(e.Item.FindControl("managechecklist"), LinkButton)
> >
> > lbtnManageCheckist.visible = False
> > If lbtnManageCheckist.CommandArgument.toString() Then
> > lbtnManageCheckist.visible = True
> > End If
> >
> > End If
> > End Sub
> >
> >
> > 2. I tried another way, here I can get to command argument value but[/color]
> setting[color=green]
> > of the link button to visible is not working:
> >
> > Sub DoItemSelect(sender As Object, e As DataListCommandEventArgs)
> >
> > If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
> > ListItemType.AlternatingItem Then
> > ' Retrieve the Label control in the current DataListItem.
> > Dim lbtnManageCheckist As LinkButton =
> > CType(e.Item.FindControl("managechecklist"), LinkButton)
> >
> > lbtnManageCheckist.visible = False
> > If lbtnManageCheckist.CommandArgument.toString() Then
> > lbtnManageCheckist.visible = True
> > End If
> >
> > End If
> > End Sub
> >
> >
> >
> >
> > Can anyone advise what is the better way to get this thing working. I[/color][/color]
need[color=blue][color=green]
> > link button to appear in DataList on condition[/color]
> "is_measure_customchecklist"[color=green]
> > is true
> >
> >
> > Thank you...
> >
> >[/color]
>
>[/color]


Closed Thread


Similar ASP.NET bytes