By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,779 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,779 IT Pros & Developers. It's quick & easy.

hyperlinks - does an easier way exist?

P: n/a
hello everybody,
i'm posting this problem because i spent a few hours
on reading forums, newsgroups, tutorials and others
but i still dont know how to solve my problem.
It concerns displaying hyperlink in a datagrid.
Hyperlink is stored in an sql database as plain text.
my table in the database consists of 3 columns: id, text, link.
i would like to display this link as hyperlink (click and redirect to
another web place)

i'm trying to do this similarly to displaying an image (it works with
images)...so
i created a hyperlink column called hyperlink
could you tell me what i'm doing wrong? maybe there is an easier way to do
this?

<asp:DataGrid id="DataGrid2" runat="server"
OnItemDataBound="DataGrid2_ItemDataBound">
....
<asp:HyperLinkColumn DataNavigateUrlField="id" HeaderText="hyperlink"
NavigateUrl='sklep2.aspx?id=<%#
Convert.ToString(DataBinder.Eval(Container.DataIte m,"id")) %>'
</asp:HyperLinkColumn>

....
void DataGrid2_ItemCommand(object sender, DataGridCommandEventArgs e) {
System.Web.UI.WebControls.HyperLink linka = new
System.Web.UI.WebControls.HyperLink();
if((e.Item.ItemType == ListItemType.Item)||(e.Item.ItemType ==
ListItemType.AlternatingItem)){
linka.NavigateUrl = "sklep2.aspx?link="+e.Item.Cells[3].Text;
}
}

and

void BindGrid(){
string conStr = "server=\'(local)\'; trusted_connection=true;
database=\'test\'";
SqlConnection Con = new SqlConnection(conStr);
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM squad", Con);
DataSet ds = new DataSet();
da.Fill(ds,"squad");
DataGrid2.DataSource = ds;
DataGrid2.DataBind();
}
file sklep2.aspx :

void Page_Load(object sender,EventArgs e){
string LinkID = Request.QueryString["id"];
string conStr = "server=\'(local)\'; trusted_connection=true;
database=\'test\'";
SqlConnection Con = new SqlConnection(conStr);
SqlCommand Com = new SqlCommand("SELECT * FROM squad WHERE id="+LinkID,
Con);
try{
Con.Open();
SqlDataReader MYDATA;
MYDATA = Com.ExecuteReader(CommandBehavior.CloseConnection) ;
Response.Write("<a
href="+MYDATA["link"].ToString()+">link</a>");
Con.Close();
}
catch(SqlException EXEPT){
Span1.InnerHtml = "READING Failed. DETAILS: "+EXEPT.ToString();
}}

best regards,
p.

Nov 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.