Reply to comment

I still have not access to my hyperlink which is inside of templ

I implemented your code in my code behind to have access to hyperlink which is inside a templatefield of detailsview control but your code returns null

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="products.aspx.cs" Inherits="products" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>





EnableModelValidation="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="GROUPNAME" ForeColor="#333333" GridLines="None"
>


SortExpression="GROUPNAMEF" >


Visible="False" />









EnableModelValidation="True" CellPadding="4" ForeColor="#333333"
GridLines="None" AutoGenerateColumns="False" DataKeyNames="SETNUM"
onselectedindexchanged="GridView2_SelectedIndexChanged">


SortExpression="SETNAME" Visible="False" />
SortExpression="SETNAMEF" >


SortExpression="SETNUM" >










onclick="Button1_Click" Text="نمايش ليست آزمايشگاهها" />
AutoGenerateRows="False" CellPadding="4" DataKeyNames="ID"
DataSourceID="SqlDataSource3" EnableModelValidation="True" ForeColor="#333333"
GridLines="None" Caption="مجموعه تجهيزات" CaptionAlign="Top"
onprerender="DetailsView1_PreRender"
ToolTip="با کليک کردن روي اعداد پايين صفحه ميتوانيد تمام کالاهاي مجموعه را مشاهده نماييد"
Width="75%" ondatabinding="DetailsView1_DataBinding"
ondatabound="DetailsView1_DataBound">





ReadOnly="True" SortExpression="ID" />

SortExpression="TITLEF" />
SortExpression="STANDARD" />





HtmlEncode="False" />

SortExpression="DTIME" />
HeaderText="بروشورفارسي" />
SortExpression="FMNURL" />












onclick="Button2_Click" Text="نمايش ليست آزمايشگاهها" />
   
   
   
   
   
ConnectionString="<%$ ConnectionStrings:LocalSqlServer %>"
SelectCommand="SELECT * FROM [EQUIP] WHERE ([SETNUM] LIKE '%' + @SETNUM + '%') ORDER BY [CATNO]">

PropertyName="SelectedValue" Type="String" />

ConnectionString="<%$ ConnectionStrings:LocalSqlServer %>"
SelectCommand="SELECT DISTINCT [GROUPNAMEF], [GROUPNAME] FROM [LABSET] ORDER BY [GROUPNAMEF]">
ConnectionString="<%$ ConnectionStrings:LocalSqlServer %>"

SelectCommand="SELECT [SETNAME], [SETNAMEF], [SETNUM] FROM [LABSET] WHERE ([GROUPNAME] = @GROUPNAME)">

PropertyName="SelectedValue" Type="String" />



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class products : System.Web.UI.Page
{
string sJavaScr = "function SizeIMGS() {\n" +
"for (j =3; j < document.images.length; j++) {\n" +
"//if(j%6==0)\n" +
"SizeIMG(document.images[j], 175);}\n" +
"return;}\nfunction SizeIMG(img1, newW) {\n" +
"w = img1.width;h = img1.height;if (h == 0) h = newW;" +
"k = w / newW;img1.height = h / k;img1.width = newW;}\nSizeIMGS();";

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

Button1.Visible = false;
Button2.Visible = false;
string slang=Request.QueryString["lang"];
if (slang == "en" || slang == "EN")
{
Button2.Text = "Show Lab Sets";
Button1.Text = "Show Lab Sets";

DetailsView1.Fields[1].HeaderText = "Cat. No.";
DetailsView1.Fields[2].HeaderText = "Product Name";
DetailsView1.Fields[3].HeaderText = "Standards";
DetailsView1.Fields[4].HeaderText = "Photo";
DetailsView1.Fields[5].HeaderText = "Description";
DetailsView1.Fields[6].HeaderText = "Video";
DetailsView1.Fields[7].HeaderText = "Delivery Time";
//DetailsView1.Fields[8].HeaderText = "Brochure";
DetailsView1.Fields[9].HeaderText = "Manual";
DetailsView1.Fields[10].HeaderText = "Enquiry";
DetailsView1.Fields[11].HeaderText = "More Info";

DetailsView1.Caption = "Equipments of This Set:";

BoundField bfr1 = (BoundField)DetailsView1.Fields[2];
bfr1.DataField = "TITLE";
bfr1.HeaderText = "Product Name";
bfr1.ReadOnly = true;
BoundField bfr5 = (BoundField)DetailsView1.Fields[5];
bfr5.DataField = "DESC";
bfr5.HeaderText = "Specifications";
bfr5.ReadOnly = true;
HyperLinkField bfr8 = (HyperLinkField)DetailsView1.Fields[8];
bfr8.DataNavigateUrlFields=new string[] {"BRURL"};
bfr8.DataTextField = "BRURL";
bfr8.HeaderText = "Brochure";

HyperLinkField bfr9 = (HyperLinkField)DetailsView1.Fields[9];
bfr9.DataNavigateUrlFields = new string[] { "MNURL" };
bfr9.DataTextField = "MNURL";
bfr9.HeaderText = "Manual";

//TemplateField bfr10 = (TemplateField)DetailsView1.Fields[10];

// bfr10.ItemTemplate=
//
// HyperLink hplnk = (HyperLink)DetailsView1.Rows[10].Cells[0].FindControl("HyperLink_Quote");
//if (hplnk.NavigateUrl != "")
//{
// string su = hplnk.NavigateUrl;
// su.Replace("fa", "en");
// hplnk.NavigateUrl = su;
//}

//changing gridview fields

BoundField Grid_b2=(BoundField)GridView1.Columns[0];
Grid_b2.DataField = "GROUPNAME";
Grid_b2.HeaderText = "Laboratories List"; //"";

CommandField Grid_b3 = (CommandField)GridView1.Columns[2];
//Grid_b3.DataField = "GROUPNAME";
Grid_b3.SelectText = "Show Category"; //"";

//changing gridview fields

BoundField Grid_b4 = (BoundField)GridView2.Columns[1];
Grid_b4.DataField = "SETNAME";
Grid_b4.HeaderText = "TEST SET SNAME";

CommandField Grid_b5 = (CommandField)GridView2.Columns[3];
//Grid_b3.DataField = "GROUPNAME";
Grid_b5.SelectText = "Show Products"; //"";

mytable.Attributes["Dir"] = "ltr";

}

}

}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

}

protected void DetailsView1_PreRender(object sender, EventArgs e)
{
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "SCRIPT", sJavaScr, true);
// GridView1.Visible = false;
// GridView2.Visible = false;
// Button1.Visible = true;
// Button2.Visible = true;
// DetailsView1.Visible = true;
if (DetailsView1.DataItemCount > 0)
{
Button1.Visible = true;
Button2.Visible = true;
}

}
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.Visible = true;
GridView2.Visible = true;
Button1.Visible = false;
Button2.Visible = false;
// DetailsView1.Visible = false;
}
protected void Button2_Click(object sender, EventArgs e)
{
Button1_Click(sender, e);
}
protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
{
GridView1.Visible = false;
GridView2.Visible = false;

}

private Control FindControlRecursive(Control ctlRoot, string sControlId)
{

// if this control is the one we are looking for, break from the recursion

// and return the control.

if (ctlRoot.ID == sControlId)
{

return ctlRoot;

}

// loop the child controls of this parent control and call recursively.

foreach (Control ctl in ctlRoot.Controls)
{

Control ctlFound = FindControlRecursive(ctl, sControlId);

// if we found the control, return it.

if (ctlFound != null)
{

return ctlFound;

}

}

// we never found the control so just return null.

return null;

}
protected void DetailsView1_DataBound(object sender, EventArgs e)
{

}
protected void DetailsView1_DataBinding(object sender, EventArgs e)
{
// search for the control by it's ID.

Control controlToFind = FindControlRecursive(DetailsView1, "DetailsView1:HyperLink_Quote");

// make sure something was returned (ie: not null).

if (controlToFind != null)
{

// cast the control to a TextBox.

HyperLink hl = (HyperLink)controlToFind;
hl.Text = "do something!";

// do something with the TextBox control.

}
else
DetailsView1.Visible = false;

}
}

can anybody help me?

Reply