473,382 Members | 1,651 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Gridview Selection

Is it possible to select an item on a gridview by clicking on it and
then being able to click a link for example that says EditOrder in a
treeview and have the EditOrder page open up viewing what you selected
in the gridview? My EditOrder link is in a sitemap so I don't know if
it is possible becuase you would almost have to pass a variable to the
sitemap. What would be the easiest way to accomplish it?

Feb 21 '06 #1
1 5097
The best approach would be be to add the Edit link in the GridView
rather than in the TreeView. Adding values to the query string is easy
inside the GridView, just add a HyperLinkField and populate the
DataNavigateURLFields and DataNavigateUrlFormatString. However, if you
are stuck using a TreeView to navigate to the Edit Page, you have to
update the URL programatically (someone correct me if I'm wrong about
this). Here's a form with a GridView control and a TreeView.

<form id="form1" runat="server">
<div>
<asp:TreeView ID="TreeView" runat="server"
DataSourceID="SiteMapDataSource">
</asp:TreeView>

<asp:GridView ID="GridView" runat="server"
DataSourceID="SqlDataSource"
OnSelectedIndexChanged="GridView_SelectedIndexChan ged">
<Columns>
<asp:CommandField ShowSelectButton="True" />
</Columns>
<SelectedRowStyle BackColor="#FFFFC0" />
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:pubsConnectionString
%>"
SelectCommand="SELECT [ord_num], [ord_date], [qty] FROM
[sales]">
</asp:SqlDataSource>
</div>
<asp:SiteMapDataSource ID="SiteMapDataSource" runat="server" />
</form>

And here's the Web.Sitemap:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="~/Default.aspx" title="Home">
<siteMapNode url="~/EditOrder.aspx" title="Edit Order" />
</siteMapNode>
</siteMap>

To set the querystring on the EditOrder link update it when the
selected item on the grid changes:

protected void GridView_SelectedIndexChanged(object source, EventArgs
e)
{
GridViewRow row = GridView.SelectedRow;
string order_number = row.Cells[1].Text;

TreeNode tn = TreeView.FindNode(Server.HtmlEncode("Home/Edit
Order"));
tn.NavigateUrl = string.Format("~/EditOrder.aspx?ord_num={0}",
order_number);
}

You can improve on the code to get the order_number and find the
TreeNode, but the key is updating the NavigateURL each time the
selected item changes. It's a little ugly, but if you need to use a
TreeView bound to a sitemap file it may be your only option.

-Carl

Feb 21 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mateo | last post by:
Hello, I have a GridView inside which i want to show 3 dropdownList (one for each Column). So i've created 3 TemplateField Continent Country City
1
by: bill tie | last post by:
I have two dropDownLists A and B outside a gridView. A selection made in ddlA causes ddlB to be populated with data from the database. The gridView is populated with data according to a...
3
by: tarscher | last post by:
Hi all, I have a gridview populated with data coming from a dataset (created via the wizard). The data shown in the gridview is dependent on the the choice of a control (dropdown with...
10
by: Carlos | last post by:
Hi all, I have a form with an input radio control in a template field. When the user selects an option, and press a button the selection disappears.. I would like the selection to persist after...
4
by: Randy Smith | last post by:
Hi, I would like to limit my user selection to only one row in the GridView at a time. Is there any way to set this? TIA, Randy
0
by: New2ASP | last post by:
Thanks everyone in advance for your help. I am fairly new to web development but an experienced window-based developer. Here's the structure of my Gridview Column 1 : Checkbox with SelectAll...
0
by: sharonrao123 | last post by:
hello all, I have a parent gridview company and in this one a nested gridview people, Is it possible to allow the user to select one row or multiple rows from the people gridview using a check box...
0
geo039
by: geo039 | last post by:
I have a usercontrol with textboxes. Most of which refer to a gridview on selection. A user clicks a looking glass and a gridview appears to select items (like a dropdown). The page loads with...
0
by: Rasika WIJAYARATNE | last post by:
Hi everyone, I have two grid-views and I am trying to populate the data on gv2 based on the selection in gv1. However when a row is selected in gv1, it doesn't populate the gv2 with data. I have...
13
by: SAL | last post by:
Hello, I'm trying to include a popup in the ItemTemplate of a gridview row. The ItemTemplate for the field contains a textbox and when the user clicks in the textbox I want a popup panel to show...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.