Gridview Hyperlink Field needs to include value from a previous gridview and a field value

Hi all

Hope you can help, here is what I'm trying to do.

I have a gridview on a page that contains a value (PracticeCode)

I use this value as a parameter to filter an additional GridView (Gridview2). Now what I also want to do is take that value (PracticeCode) and use it in as part of the URL for a hyperlink field in GridView2 concatenatint it with the value of a Gridview field called Documentname so that:

Hyperlink field URL Is "/store/" & PracticeCode & "/" and DocumentName

Anyone know how to do this

 regards

chubster


it wasn't me, a big boy did it and ran away
0
chubster
9/6/2007 11:02:16 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

1 Replies
1091 Views

Similar Articles

[PageSpeed] 19

Put this into your web form:

 

    <table style="width: 95%" cellpadding="3">
        <tr>
            <td>
                <asp:GridView ID="GridView1" runat="server" DataKeyNames="Id" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
                    <Columns>
                        <asp:CommandField ShowSelectButton="True" />
                    </Columns>
                </asp:GridView>
            </td>
            <td>
                <asp:GridView ID="GridView2" runat="server">
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:HyperLink ID="myHL" runat="server" Text="My Hyperlink" NavigateUrl='<%# "SomeFolder/" + SelectedId + "/SomePage.aspx" %>'></asp:HyperLink>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                </asp:GridView>
            </td>
        </tr>
    </table>

 Code Behind:

        public int SelectedId
        {
            get 
            { 
                ViewState["myid"] = (ViewState["myid"]==null) ? 0 : ViewState["myid"];
                return (int) ViewState["myid"]; 
            }
            set { ViewState["myid"] = value; }
        }
	
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GridView1.DataSource = CreateDataSet();
                GridView1.DataBind();
            }
        }

        private DataSet CreateDataSet()
        {
            DataSet ds = new DataSet();
            DataTable mytable = new DataTable();
            mytable.Columns.Add("Id", typeof(int));
            mytable.Columns.Add("Name", typeof(string));
            mytable.Columns.Add("Date", typeof(DateTime));

            DataRow dr;
            dr = mytable.NewRow();
            dr["Id"] = 1;dr["Name"] = "First";dr["Date"] = DateTime.Now;
            mytable.Rows.Add(dr);

            dr = mytable.NewRow();
            dr["Id"] = 2;dr["Name"] = "Second";dr["Date"] = DateTime.Now;
            mytable.Rows.Add(dr);

            dr = mytable.NewRow();
            dr["Id"] = 3;dr["Name"] = "Third";dr["Date"] = DateTime.Now;
            mytable.Rows.Add(dr);

            ds.Tables.Add(mytable);

            return ds;
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            SelectedId = (int) GridView1.DataKeys[GridView1.SelectedIndex]["Id"];
            ReloadDetail();
        }

        private void ReloadDetail()
        {
            GridView2.DataSource = CreateDataSet();
            GridView2.DataBind();
        }
 
0
Hans
9/6/2007 2:58:52 PM
Reply:

Similar Artilces:

How can I add 2 fields value to 1 fields value in a GridView?
Hi all!I have one access database named=Medlemmar.mdb and Tablename=TidBokning and with some columns ex. "Bokad_For" and "Plats".Let say that "Bokad_For" contains value "Group2" and "Plats" contains value "Stockholm".Now I want to make this 2 value to 1 fileds like this: "Bokad_For" contains value "Group2Stockholm"How can I do that?I use asp.net 2.0 and C#.I tried with Eval("Bokad_For") and somthing, but Eval works only in Templates (I guess) I cant get Templates to work in my GridView.i'm newbee in this and think I need some help here :-) ?Thanks for all help!Micael Roxenhall You can sol...

How to add values to template control fields textbox control in GridView..
Hi all,    <asp:GridView ID="GridView1" EnableViewState="true" DataKeyNames="LicenseTemplateID"                       runat="server" AutoGenerateColumns="False" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"                       Width="345px">                       <Columns>                           <asp:Templa...

Displaying an image in gridview field dependant of field value
Firstly I apologise in advance for my lack of knowledge, this is what I'm trying to achieve: I have a gridview (orders) that is populated based on a selection in another (customer), one of the fields is orderStatus this is an integer (0=outstanding, 1=in progress 2=complete) instead of displaying the integer value in my grid I would like to display an appropriate icon. I have managed to get the value of the field using:1 Protected Sub order_Rowcreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles order.RowCreated 2 If e.Ro...

How do I obtain the value of a hyperlink field in a gridview?
I noticed that when I try to ascertain the value of  column 1 in my datagrid, which is a hyperlink field, it comes up blank.  GridView1.Rows(0).Cells(0).Text. After reading a bit I gathered that I am supposed to convert it to a template and then use findcontrol method. Can someone point out how to use findcontrol and the syntax?   Use the FindControl() method inside the Cell of the GridViewRow that contains the Hyperlink.Private hl As HyperLink = CType(GridView1.Rows(0).Cells(0).FindControl("controlID"), HyperLink)James Hearst.NET Application Developer Does your line assu...

Get the value of GridView field from a hyperlink.
Hi guys, In my GridView I have a TemplateField and inside that I have a LinkButton and HyperLink. Now what I want to do is to be able to get the value of another field in that GridView (ID of that table) and store it in a session variable and then redirect to the next page and on the next page load that record for that ID in a DetailsView. Now how can I get the value of the first column in GridView when on second column I click on a hyperlink to store and pass it in the session variable ? I can get the ID in this way but either way user would be exposed to the ID, I don't want they would...

Sorting a GridView by a second field, if the values of the first field are equal
I have a simple league table GridView, where the rows are initially sorted by the 'Points' field. leagueTable.Sort("Points", SortDirection.Descending) What I want to do is if there are two rows with the same number of points for example, they (just the 2 rows) need to be sorted according to the field 'GoalDifference' .Is there any simple way to do this? Thanks.  Hi:   Please try this: leagueTable.Sort("Points,GoalDifference", SortDirection.Descending) RegardsSincerely,Allen ChenMicrosoft Online Community SupportPlease remember...

gridview: filling a textbox with a value of a field by clicking on a button in that field
Hi, I have created a gridview filled with data from a database. Now when I go into edit mode, I want to click on button1 in the Templatefield "text" and the text should be shown in a textbox below the grid ready to edit. But I get errors when I want to do an onclick event with the button, saying "Id Expected".  I also don't know how to get the value of text into a variable or which variable contains the value of "text" and how to pass it to the textbox below. Maybe there's a better way to do this then I have in mind? t...

Can a field in Gridview be a Hyperlink field as well as Template field?
I have to add Template field  to Gridview and use data binding statement such as "<%# GetData(Eval("DType").ToString())%>" in the ItemTemplate. so that column retrieve/shows GetData("DType") values. When user clicks on this column it should redirect the user to another page, showing selected/clikced datarow . I think it is to do with Dynamic Hyperlink Field. I like to know can a column be a Hyperlink field as well as Template field so that i can use data binidng statement as above and do hyperlink task as well. your quick suggestion ...

Hyperlink Field -Get the cell Value from gridview
Hi I have one gridview and i have a Hyperlink field. When i click the hyperlink i'll be redirect to another page. I need to pass the second cell value from the gridview (maybe by querystring parameter) to this page. Any help, please? Thank you Mario Lopes   <asp:HyperLinkField DataNavigateUrlFields="SecondCellDataFieldName" DataNavigateUrlFormatString="~/TargetPage.aspx?id={0}" /> where SecondCellDataFieldName is the FieldName that is bound to the second cell ...  Regards,Anas Ghanem.Note:Please Don't hesitate to click "R...

Only select few fields to gridview when clicking some fields on gridview remaining fields should be in a popup window
Pls help me out this. I am having a table of 30 fields.. i dont want to show everyfields in the gridview that would be very messy. i need to show only 2 or 3 fields in the gridview and if the user click on any of the field in the gridview the 30 fields should be shown in a small size window....  And the small size window should have a button(e.g: approved) to update a field(approved field : no to yes) in the table...... Is there any possibilities to do this..if so pls guide me... Thanks in advance Hi muthulakshmanan , Add some boundfield to GV, which used to show only few co...

How to automatically copy the value of a gridview row to a field in the gridview footer row
Hello,  How to automatically copy the existing value displayed in a gridview row to a field in the gridview footer row.  Both fields are of the same type.  The gridbew row is used to modify information and the footer row is used to add new information to the db. Gridview1.FindControl("WorkOrderID) GridView1.FooterRow.FindControl("NewWorkOrderID")   Thank you,ptown check this link.. http://msdn2.microsoft.com/en-us/library/aa728895(VS.71).aspxRegards,Punithkumar 1 - turn column into template 2 - Add a label to footer template 3 - Say yo...

There is a Gridview Control in the tmplate field of another GridView Control.
    For instance,a gridview displays the information of the  students in a class.A table is recording the information except their mark.There is another table recording the mark of the students whose foreign key is the primary key of the previous table.   string strSQLconnection=".................."; SqlConnection sqlCononection=new SqlConnection(strSQLconnection); SqlCommand sqlCommand=new SqlCommand("select * from stuendent where classID=1",sqlConnection); SqlConnection.Open(); SqlDataReader reader=sqlCommand.ExecuteReader(); GridVie...

GridView Field Value
How can the value of a boundfield or templatefield be accessed in a gridview's RowDataBound event? Please kindly provide code sample. Thanks.  Please mark the post(s) that have helped you as "Answer" For template field, you need use FindControl to get the reference of the control in the template. For example, a button whose ID is SelectBtn in the template field,Button bt = e.Row.FindControl("SelectBtn") as Button;   For Bound field, you need know its index. For instance, the first column you want to refer,string str = e.Row.Cells[0].Text ...

GridView child of GridView
I have a Parent GridView and when you click in the Edit one of the columns has a Template Field which has a Child GridView. When you click Edit on the Child GridView I have a Template Field that has a TextBox. How to I retreive this value of the TextBox? GridViewParent-- GridViewChild (Edit - Template Field containing this GridViewChild)----- TextBox inside Template Field in GridViewChild. Thank you.Peace in ChristMarco Napolihttp://www.ourlovingmother.org What you can do as a solution is to override the RowDataBound and try to find the child GridView control. Once you get a reference to...

Web resources about - Gridview Hyperlink Field needs to include value from a previous gridview and a field value - asp.net.presentation-controls

Hyperlink - Wikipedia, the free encyclopedia
A hyperlink points to a whole document or to a specific element within a document. Hypertext is text with hyperlinks. A software system for viewing ...

SA Supreme Court rules Dr Janice Duffy was defamed by Google through its hyperlinks, auto-complete and ...
A FORMER SA Health researcher has won a six-year legal battle against Google, proving she was defamed by the internet giant due to the way it ...

Banned hyperlinks could cost you $11,000 a day
The Australian communications regulator says it will fine people who hyperlink to sites on its blacklist, which continues to be controversially ...

ANALYSIS - Supreme Court hyperlink decision a victory for free speech
A hyperlink by itself should never be seen as 'publication' of other content, the Supreme Court said. But when it comes to libel the court did ...

Review: HyperLink is a great, inexpensive steel bracelet for the Apple Watch
Apple's own stainless steel link bracelet is too expensive for many of us to consider. HyperLink, however, is a less expensive alternative that ...

Apple's 'audio hyperlink' tech can control devices with inaudible sonic pulses
An Apple patent filing published by the U.S. Patent and Trademark Office on Thursday describes a method of encoding hyperlinks into an audio ...

Patent troll sending out invoices for image hyperlinks
A company named Vuestar thinks everyone who links images to pages on the Web …

How Effective Hyperlinks Can Help Your Blog
... link text explain exactly where the link is leading you or does it say something generic like click here ? When I saw Writing Effective Hyperlinks ...

Gmail's Shortcut for Inserting Hyperlinks
... doesn't mean Google shouldn't improve them. Many people complained that Gmail's rich text editor doesn't have a shortcut for inserting hyperlinks ...

Scientology loss keeps hyperlinks legal
The Church of Scientology loses a courtroom battle to compel a Dutch writer and her ISP to remove postings from a Web site, in a ruling that ...

Resources last updated: 1/5/2016 11:46:39 AM