C# .NET - Gridview : generating dynamic navigateurl for a hyperlink field

Asked By Shyam sasidharan
26-Apr-09 11:49 PM
hi i have a grid view which has bound fields and a Hyperlink field. i want to dynamically input the Navigateurl field as "custdb:\\iq="dynamically generated no" . This no is the data that the result set displays in the same column!! say the no is 87750 then i have to generate the navigateurl for the hyperlink field as "custdb:\\iq=87750" so that a softwate installed in the computer pops up!!

please help!!

easy  easy

27-Apr-09 12:01 AM
Hi

try this code

<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="ID"
DataNavigateUrlFormatString="userDetail.aspx?ID={0}" />
</Columns>
</asp:GridView>

Note: DataNavigateUrlFields is data column name which are bind to to gridview and DataNavigateUrlFormatString="userDetail.aspx?ID={0}"
then you need assign that based on index base, becuase of you can give multi parameter also.

That' it

Thank you

re  re

27-Apr-09 12:22 AM

use this way put a hyperlink control in gridview and set url in code behind

<asp:TemplateField>
 <ItemTemplate>
  <asp:HyperLink ID="lnkUrl" runat="server" NavigateUrl="YourUrl"></asp:HyperLink>
 </ItemTemplate>
</asp:TemplateField

protected void ListRowDataBound(object sender, GridViewRowEventArgs e)
        {
            if ((e.Row != null) && (e.Row.RowType == DataControlRowType.DataRow))
            {
                Order order = e.Row.DataItem as Order; // Assuming the GridView

                if (order != null)
                {
   if (order.ClaimType == "P")
   {
    ((Hyperlink)e.Row.FindControl("lnkUrk")).NavigateUrl = 'put here your dynamic url';
   }
   else if (order.ClaimType == "I")
   {
    ((Hyperlink)e.Row.FindControl("lnkUrk")).NavigateUrl = 'put here your dynamic url';
   } 
                }
            }
        }

Use the DataTextField property along with the DataNavigateUrlFormatString  Use the DataTextField property along with the DataNavigateUrlFormatString

27-Apr-09 01:15 PM
<asp:GridView ID="grdData" runat="server">
...
                <asp:HyperLinkField DataNavigateUrlFields="custdb"  ID="custlink"
DataTextField=dynamicallygeneratednocolumnname
                    DataNavigateUrlFormatString="custdb:\\iq={0}" />
           . ..
        </asp:GridView>


abother one  abother one
27-Apr-09 01:18 PM
Please read below lines from user's question and check your answer whether it meets the user's requirements.

""custdb:\\iq="dynamically generated no" . This no is the data that the result set displays in the same column!! say the no is 87750 then i have to generate the navigateurl for the hyperlink field as "custdb:\\iq=87750""

Regards.
Create New Account
help
How to use gridview control in asp.net? Hi Friends, I want to know how to use the grid view control in asp.net. give me some example. Thanks & Regards, Stephen. L hi • The GridView control is associated with the DataSource control through its DataSourceID property. • In ASP.NET 2 are designed to work with different data sources. • Enabling Editing and Deleting records in the GridView Control is as simple as setting the properties “AutoGenerateDeleteButton” and “AutoGenerateEditButton” as "True" • GridView totally supports 6 field types, they are: 1. BoundField, 2. CheckBoxField, 3. ButtonField, 4. CommandField 5. HyperlinkField, 6. ImageField and 7. TemplateField Basic Concept The basic concept behind this is when the GridView is rendered on the client machine it is rendered as a simple HTML table. Hence what the JavaScript will see a HTML table and not the ASP.Net GridView control. Hence once can easily write scripts for GridView, DataGrid and other controls once you
show data on hyperlink in gridview hello, i am working in forum project. . i have a User_Article Table with column Article_Id, User_id, Article. . i want to show article in hyperlink inside gridview. . .and when click on article it will navigate to other with the brief detail regarding server 2005. . you can use this full code to display article on another page from gridview < asp : GridView ID = "gvarticles" runat = "server" Width = "100%" AutoGenerateColumns = "false" DataKeyNames = "ARTICLE_ID" GridLines = "None" OnRowCommand = "gvarticles_RowCommand"> < HeaderStyle CssClass = "GridHeader" HorizontalAlign = "Left" / > < RowStyle CssClass = "GridViewRow" / > < AlternatingRowStyle CssClass = "GridViewAlternatingRow" / > < Columns > < asp : TemplateField HeaderText = "Article Thumbnail" HeaderStyle-Width = "120" HeaderStyle-CssClass = "griditemspadding" ItemStyle-CssClass = "griditemspadding"> < ItemTemplate > < img src Articles / <%# DataBinder.Eval(Container.DataItem, "IMAGE_NAME")%> ' width = "60" height = "60" style = " padding : 5px ; " / > < / ItemTemplate > < / asp : TemplateField > < asp : BoundField HeaderText = "Article Name" DataField = "ARTICLE_NAME" HeaderStyle-Width = "200" / > < asp : BoundField HeaderText = "Date Added" DataField = "DATEADDED" HeaderStyle-Width = "250" / > < asp : TemplateField HeaderStyle-Width = "30px"> < ItemTemplate > < asp : LinkButton ID = "btn" runat = "server" CommandName = "editemployment" CommandArgument = ' <%# Eval("ARTICLE_ID ToolTip = "Edit" Text = "Edit"> < / asp : LinkButton > < / ItemTemplate > < / asp : TemplateField > < asp : TemplateField HeaderStyle-Width = "40px"> < ItemTemplate > < asp : LinkButton ID = "btndeletearticle" runat = "server" CommandName = "deletearticle" CommandArgument
gridview checkbox and select all Hi, I want to use checkbox to my gridview. When i click select all check box the other all checkboxes in the gridview should be selected. and individuval checkbox selction . Pz help hi kiruba see the below code <asp:GridView ID = "gvTest" runat = "server" AutoGenerateColumns = "false"> <Columns> <asp TemplateField> <HeaderTemplate> <input id = "chkBoxAll" type = "checkbox" onclick = "checkAllBoxes()" / > < / HeaderTemplate> <ItemTemplate> <asp:CheckBox ID = "chkBoxChild" runat = "server" / > < / ItemTemplate> < / asp:TemplateField> <!- - The rest of your rows here - -> < / Columns> < / asp:GridView> hey to make this type of functionality , you need to define one check box in the header template of gridview. So when user will check / uncheck this checkbox all the checkboxes checked / unchecked. < asp:TemplateField
Changing specific row text color in a gridview Hi all, I have a grid view in which i have a column ACTIVE STATUS easy. . . . Can you provide me some information regarding this. . . Are you using template columns in Gridview. . . . . Or else please post your code i will modify that and will send you back. . . . This is code for my grid view. <asp:GridView ID = "gridviewviewexis" runat = "server" CellPadding = "3" AutoGenerateColumns = "False" BackColor = "White" BorderColor = "#CCCCCC" BorderStyle = "None" BorderWidth 1px" onrowdeleting = "gridviewviewexis_RowDeleting" DataKeyNames = "Sno" onrowdatabound = "gridviewviewexis_RowDataBound"> <RowStyle ForeColor = "#000066" / > <Columns> <asp:TemplateField HeaderText = "SNo"> <ItemTemplate> <asp:Label ID = "Labels" runat = "server"> <%# Container.DataItemIndex + 1 %> < / asp:Label> < / ItemTemplate> < / asp:TemplateField> <asp:BoundField DataField = "Sno" HeaderText = "Sno" SortExpression = "Sno" InsertVisible = "False" ReadOnly = "True" Visible = "false" / > <asp ButtonField CommandName = "Delete" DataTextFormatString = "greetingsadmin2.aspx?sno = {0}" HeaderText = "Action" SortExpression = "sno" Text = "Delete" / > <asp:HyperLinkField DataNavigateUrlFields = "Sno, Activestatus" DataNavigateUrlFormatString = "ActiveInactive.aspx?Sno = {0}&Activestatus = {1}" NavigateUrl = "~ / ActiveInactive.aspx" Text = "Edit 669999" Font-Bold = "True" ForeColor = "White" / > <HeaderStyle BackColor = "#006699" Font-Bold = "True" ForeColor = "White" / > < / asp:GridView> <asp:SqlDataSource ID = "SqlDataSource1" runat = "server" ConnectionString = "<%$ ConnectionStrings:MilageransConnectionString %> " SelectCommand = "pFillviewExisAdmingrid" SelectCommandType = "StoredProcedure"> < / asp:SqlDataSource> check the below code, based on the condition the gridview row color changed <asp:GridView ID = "GridView2" AutoGenerateColumns = "false" runat = "server" Width = "600" OnRowDataBound = "GridView2_RowDataBound
giv idea abt that The RowDataBound event fires when a row is bound to the gridview with data. If you want to add such a event to the gridview, you can follow the below line. < asp:GridView OnRowDataBound = "GridViewRowEventHandler" / > And then in the code behind, you can handle all the stuff that More info avilable at http: / / msdn.microsoft.com / en-us / library / system.web.ui.webcontrols.gridview.rowdatabound.aspx The RowDataBound event is raised when a data row (represented by a GridViewRow object) is bound to data in the GridView control. This allows you to provide an event-handling method that performs a custom routine modifying the values of the data bound to the row, whenever this event occurs. A GridViewRowEventArgs object is passed to the event-handling method, which allows you to access the properties bound. To access a specific cell in the row, use the Cells property of the GridViewRowEventArgs object. You can determine which row type (header row, data row, and so on) is using the RowType property. Sample: <%@ Page language = "C#" %> <script runat = "server"> void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e) { if(e.Row.RowType = = DataControlRowType.DataRow) { / / Display the company name in italics. e.Row