[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

navigation button in datagrid

Posted on 2004-11-03
30
Medium Priority
?
1,659 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:csetzkorn
  • 12
  • 11
  • 7
30 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 12481035
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
 

Author Comment

by:csetzkorn
ID: 12481049
I would like to see them in a new (browser!) window. Thanks.
0
 
LVL 28

Assisted Solution

by:mmarinov
mmarinov earned 400 total points
ID: 12481065
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:csetzkorn
ID: 12481133
Thanks for this. Is there a better way? (without requiring javascript to be enabled in the client browser)
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12481190
csetzkorn,
opening a new window is a javascript operation ( client script operation ) not server-side
B..M
0
 

Author Comment

by:csetzkorn
ID: 12481210
Exactly. it is a 'client script operation' and I do not necessarily want the client to have JavaScript switched on.
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12481253
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
 
LVL 6

Expert Comment

by:Volkan Vardar
ID: 12481381
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
 
LVL 28

Expert Comment

by:mmarinov
ID: 12481410
vardium,
cool, i didn't noticed that Target attribute is accessible to the HyperLinkColumn
this is it csetzkorn
B..M
0
 
LVL 6

Expert Comment

by:Volkan Vardar
ID: 12481427
sometimes i do the same thing. try to find a hard way, dont notice the easy way :-)
0
 
LVL 6

Expert Comment

by:Volkan Vardar
ID: 12481431
sorry i missed the last quotation
should be --> Target="_blank"
0
 

Author Comment

by:csetzkorn
ID: 12481469
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
 
LVL 28

Expert Comment

by:mmarinov
ID: 12481513
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
 
LVL 6

Expert Comment

by:Volkan Vardar
ID: 12481785
yes i think so.
there is no way to do this without javascipt if you want a button.
0
 

Author Comment

by:csetzkorn
ID: 12482068
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
 

Author Comment

by:csetzkorn
ID: 12482126
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
 
LVL 28

Expert Comment

by:mmarinov
ID: 12482323
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
 

Author Comment

by:csetzkorn
ID: 12482379
I have increased the number of points. A bit more code would be very much appreciated. Many thanks!
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12482544
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
 
LVL 6

Expert Comment

by:Volkan Vardar
ID: 12482759
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
 

Author Comment

by:csetzkorn
ID: 12483138
mmarinov,

When I try your code, I get:

Type 'System.Web.UI.WebControls.TemplateColumn' does not have a property named 'asp:Label'
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12483176
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
 

Author Comment

by:csetzkorn
ID: 12483896
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
 
LVL 28

Expert Comment

by:mmarinov
ID: 12483930
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
 
LVL 6

Expert Comment

by:Volkan Vardar
ID: 12483933
did you try my code?
0
 
LVL 6

Accepted Solution

by:
Volkan Vardar earned 600 total points
ID: 12484009
<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
 

Author Comment

by:csetzkorn
ID: 12484023
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
 

Author Comment

by:csetzkorn
ID: 12484054
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
 
LVL 28

Expert Comment

by:mmarinov
ID: 12484076
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
 

Author Comment

by:csetzkorn
ID: 12484124
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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month20 days, 2 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question