M
MattB
I'm pretty new to all of this, so please forgive me if this is a
question you've heard too many times. I'm using VS2003 and vb.net in the
codebehind.
I'm trying to make a column in my datagrid have use one of two different
templates to build a hyperlink based on what's in the data. I think I'm
really close, but I can't quite get it to work.
I've got my column working as a hyperlink as a template column, and now I
need to add logic to change that hyperlink if a certain field is not empty.
So if the field is populated, it just uses this in the aspx page:
<asp:HyperLink id=HyperLink1 runat="server" NavigateUrl='<%#
DataBinder.Eval(Container, "DataItem.node_id", "ItemList.aspx?node_id={0}")
%>' Text='<%# DataBinder.Eval(Container, "DataItem.descrip") %>'>
I've created an OnItemDataBound event that seems to be firing as I can set
the text to italic if my "item" column is empty. Now I just need to change
the hyperlink within the same if/then. Can I do this here? Is this an OK
approach?
I want my new hyperlink to be something like I have above, but using a
concatenation of three fields for the data item:
DataBinder.Eval(Container, "DataItem.ColX" & "DataItem.ColY" &
"DataItem.ColZ", "ItemShow.aspx?XYZ={0}")
So in my OnDataBoundEvent I have this section where I test for an empty cell
and for now just make the text italic:
If Not Trim(e.Item.DataItem("item")) = "" Then
'it's an item
e.Item.Cells.Item(0).Font.Italic = True
End If
Next I want to change the hyperlink here too if I can. Is that possible? I
was thinking I could do something like:
e.Item.Cells.Item(0).Controls.Hyperlink = "ItemShow.aspx?item=" &
e.Item.DataItem("ColX") & e.Item.DataItem("ColY") e.Item.DataItem("ColZ")
But that first object reference (e.Item.Cells.Item(0).Controls.Hyperlink) is
not correct. Can anyone help me here? TIA!
question you've heard too many times. I'm using VS2003 and vb.net in the
codebehind.
I'm trying to make a column in my datagrid have use one of two different
templates to build a hyperlink based on what's in the data. I think I'm
really close, but I can't quite get it to work.
I've got my column working as a hyperlink as a template column, and now I
need to add logic to change that hyperlink if a certain field is not empty.
So if the field is populated, it just uses this in the aspx page:
<asp:HyperLink id=HyperLink1 runat="server" NavigateUrl='<%#
DataBinder.Eval(Container, "DataItem.node_id", "ItemList.aspx?node_id={0}")
%>' Text='<%# DataBinder.Eval(Container, "DataItem.descrip") %>'>
I've created an OnItemDataBound event that seems to be firing as I can set
the text to italic if my "item" column is empty. Now I just need to change
the hyperlink within the same if/then. Can I do this here? Is this an OK
approach?
I want my new hyperlink to be something like I have above, but using a
concatenation of three fields for the data item:
DataBinder.Eval(Container, "DataItem.ColX" & "DataItem.ColY" &
"DataItem.ColZ", "ItemShow.aspx?XYZ={0}")
So in my OnDataBoundEvent I have this section where I test for an empty cell
and for now just make the text italic:
If Not Trim(e.Item.DataItem("item")) = "" Then
'it's an item
e.Item.Cells.Item(0).Font.Italic = True
End If
Next I want to change the hyperlink here too if I can. Is that possible? I
was thinking I could do something like:
e.Item.Cells.Item(0).Controls.Hyperlink = "ItemShow.aspx?item=" &
e.Item.DataItem("ColX") & e.Item.DataItem("ColY") e.Item.DataItem("ColZ")
But that first object reference (e.Item.Cells.Item(0).Controls.Hyperlink) is
not correct. Can anyone help me here? TIA!