Gridview : generating dynamic navigateurl for a hyperlink field

Asked By Shyam sasidharan
26-Apr-09 11:49 PM
Earn up to 0 extra points for answering this tough question.
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

Ravenet Rasaiyah replied to Shyam sasidharan
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

Web Star replied to Shyam sasidharan
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

[)ia6l0 iii replied to Shyam sasidharan
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
Perry replied to Ravenet Rasaiyah
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