navigation button in datagrid

Dear all,

At the moment I am using something like this within a datagrid:

<asp:HyperLinkColumn DataNavigateUrlField="faq_uid" DataNavigateUrlFormatString="faq_details.aspx?faq_uid={0}" DataTextField="question" HeaderText="Question"> <HeaderStyle Font-Bold="True"></HeaderStyle> </asp:HyperLinkColumn>

to enable the navigation to the details of an item. I would like to implement the same functionality with a button that has written on it: “More Details”. Any pointers would be very much appreciated. Many thanks in advance.

Chris
csetzkornAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mmarinovCommented:
Hi csetzkorn,

do you want to see this faq_details in a new window or you wanted to see them within the grid as nested datagrid ?

Regards!
B..M
0
csetzkornAuthor Commented:
I would like to see them in a new (browser!) window. Thanks.
0
mmarinovCommented:
csetzkorn,

you can try this

<asp:HyperLinkColumn DataNavigateUrlField="faq_uid" DataNavigateUrlFormatString="javascript: window.open('faq_details.aspx?faq_uid={0}'); return false;" DataTextField="question" HeaderText="Question"> <HeaderStyle Font-Bold="True"></HeaderStyle> </asp:HyperLinkColumn>

B..M
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

csetzkornAuthor Commented:
Thanks for this. Is there a better way? (without requiring javascript to be enabled in the client browser)
0
mmarinovCommented:
csetzkorn,
opening a new window is a javascript operation ( client script operation ) not server-side
B..M
0
csetzkornAuthor Commented:
Exactly. it is a 'client script operation' and I do not necessarily want the client to have JavaScript switched on.
0
mmarinovCommented:
csetzkorn,

so you can use normal <a> tag then with target attribute and this will open the new window
in this case you have to use asp:templatecolumn instead of HypeLinkColumn

B..M
0
Volkan VardarSoftware Team LeaderCommented:
use Target="_blank

<asp:HyperLinkColumn DataNavigateUrlField="faq_uid" DataNavigateUrlFormatString="faq_details.aspx?faq_uid={0}" DataTextField="question" HeaderText="Question"> <HeaderStyle Font-Bold="True" Target="_blank></HeaderStyle> </asp:HyperLinkColumn>

good luck
0
mmarinovCommented:
vardium,
cool, i didn't noticed that Target attribute is accessible to the HyperLinkColumn
this is it csetzkorn
B..M
0
Volkan VardarSoftware Team LeaderCommented:
sometimes i do the same thing. try to find a hard way, dont notice the easy way :-)
0
Volkan VardarSoftware Team LeaderCommented:
sorry i missed the last quotation
should be --> Target="_blank"
0
csetzkornAuthor Commented:
Just tried it. The Target attribute is NOT! accessible to the HyperLinkColumn.

BTW I would like to use a button rahter than a hyperlink (see original question). The latter works fine ...
0
mmarinovCommented:
csetzkorn,

what do you mean that is not accessible? this line is taken from MSDN:
            <asp:HyperLinkColumn
                 HeaderText="Select an Item"
                 DataNavigateUrlField="IntegerValue"
                 DataNavigateUrlFormatString="detailspage.aspx?id={0}"
                 DataTextField="PriceValue"
                 DataTextFormatString="{0:c}"
                 Target="_blank"/>

also if you want to use button i'm afraid you have to use javascritp :(

B..M
0
Volkan VardarSoftware Team LeaderCommented:
yes i think so.
there is no way to do this without javascipt if you want a button.
0
csetzkornAuthor Commented:
This works:

 <asp:HyperLinkColumn
                 HeaderText="Select an Item"
                 DataNavigateUrlField="IntegerValue"
                 DataNavigateUrlFormatString="detailspage.aspx?id={0}"
                 DataTextField="PriceValue"
                 DataTextFormatString="{0:c}"
                 Target="_blank"/>

but your old proposal didn't work:

<asp:HyperLinkColumn DataNavigateUrlField="faq_uid" DataNavigateUrlFormatString="faq_details.aspx?faq_uid={0}" DataTextField="question" HeaderText="Question"> <HeaderStyle Font-Bold="True" Target="_blank"></HeaderStyle> </asp:HyperLinkColumn>

anyway, I guess I have to assume that the user uses javascript ...




0
csetzkornAuthor Commented:
I think some confusion has arisen here. My original code works:

<asp:HyperLinkColumn DataNavigateUrlField="faq_uid" DataNavigateUrlFormatString="faq_details.aspx?faq_uid={0}" DataTextField="question" HeaderText="Question"> <HeaderStyle Font-Bold="True"></HeaderStyle> </asp:HyperLinkColumn>

However, I would like to replace the link with a button with the text ‘More Details’.

Thanks again.
0
mmarinovCommented:
csetzkorn,

the you have to use asp:TemplateColumn
create ItemDataBound event and add the onclick event to it to open the javascript

btn.Attributes.Add("onclick", "window.open('faq_details.aspx?faq_uid=" + your id column value + "'_); return false;" );

B..M
0
csetzkornAuthor Commented:
I have increased the number of points. A bit more code would be very much appreciated. Many thanks!
0
mmarinovCommented:
csetzkorn,

check this:

<asp:TemplateColumn>
    <asp:Label id="faqUid" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "faq_uid") %>'></asp:Label>
    <asp:Button id="btnMoreDetails" Text="MoreDetails" runat="server"></asp:Button>
</asp:TemplateColumn>

create ItemDataound event for the datagrid and in it write down

if ( e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem )
{
    Button btn = (Button)e.Item.FindControl("btnMoreDetails");
    Label lbl = (Label)e.Item.FindControl("faqUid");
    btn.Attributes.Add ( "onclick", "window.open('faq_details.aspx?faq_uid=" + lbl.Text+ "'); return false;" );
}

B..M
0
Volkan VardarSoftware Team LeaderCommented:
it should be :

<asp:HyperLinkColumn DataNavigateUrlField="faq_uid" DataNavigateUrlFormatString="faq_details.aspx?faq_uid={0}" DataTextField="question" HeaderText="Question" Target="_blank"><HeaderStyle Font-Bold="True"></HeaderStyle>
</asp:HyperLinkColumn>

try this
0
csetzkornAuthor Commented:
mmarinov,

When I try your code, I get:

Type 'System.Web.UI.WebControls.TemplateColumn' does not have a property named 'asp:Label'
0
mmarinovCommented:
csetzkorn,

I'm really sorry ( on of that bad days :( )

put the asp:Label and asp:button in

<asp:TemplateColumn>
    <itemTemplate>
        here
    </itemTemplate>
</asp:TemplateColumn>

B..M
0
csetzkornAuthor Commented:
Ok, I have this:

aspx file:

<asp:TemplateColumn>
<itemTemplate>
<asp:Label id="faqUid" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "faq_uid") %>'></asp:Label>
<asp:Button id="more_details" Text="More Details" runat="server"></asp:Button>
</itemTemplate>
</asp:TemplateColumn>

code behind file:

public void Item_Bound(Object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Button btn = (Button) e.Item.FindControl("more_details");
Label lbl = (Label) e.Item.FindControl("faqUid");
btn.Attributes.Add ( "onclick", "window.open('faq_details.aspx?faq_uid=" + lbl.Text+ "'); return false;" );
}
}

Unfortunately it doesn't work. I also don't understand what the ItemDataBound event has to do with my problem. As far as I understand it allows you to access the data before the item is displayed in the control.

Thanks.
0
mmarinovCommented:
csetzkorn,

the code above add a client script to your button before it is displayed on the page
so when you click on the button to open a new window

what is the result of the code above ?

B..M
0
Volkan VardarSoftware Team LeaderCommented:
did you try my code?
0
Volkan VardarSoftware Team LeaderCommented:
<asp:TemplateColumn>
<itemTemplate>
<input onclick="window.open('faq_details.aspx?faq_uid=<%# DataBinder.Eval(Container.DataItem, "faq_uid") %>'); return false;" name="more_details" id="more_details" type="submit" value="More Details" />
</itemTemplate>
</asp:TemplateColumn>

what about this one?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
csetzkornAuthor Commented:
vardium,

Yes, your code works but I already got this working with my code above (see original post). the diffrence is that you open a new window. Thanks anyway.

0
csetzkornAuthor Commented:
Vardium,

Your code:

<asp:TemplateColumn>
<itemTemplate>
<input onclick="window.open('faq_details.aspx?faq_uid=<%# DataBinder.Eval(Container.DataItem, "faq_uid") %>'); return false;" name="more_details" id="more_details" type="submit" value="More Details" />
</itemTemplate>
</asp:TemplateColumn>

does what I want. Many thanks.
0
mmarinovCommented:
great varium, i haven't think of input control
but csetzkorn, i'm just curious - is the code i've posted didn't act the same ?

B..M
0
csetzkornAuthor Commented:
mmarinov,

The code you have given me (the one I have posted) didn't thorw any errors but didn't do anything.

Thanks a lot for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.