C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




how to specify the hyperlink url to view documents which is shown in a datagrid


Posted Date: 11 Aug 2008      Total Responses: 3

Posted By: Sidewinder2       Member Level: Gold     Points: 1


Hello There!,

First of all through my web form i have stored some text document's name in the database (which had been attached as a attachment in my web form through Html file input)

Now i am retrieving those document's name and populating it in a datagrid. all i need is to view the document's content when some body clicks on a document name in a datagrid.

and i don't want to save those documents with my project before viewing

currently my code is,


protected void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{

e.Item.Cells[0].Attributes.Add("style", "cursor:hand");
HyperLink lnk = new HyperLink();
string str = e.Item.Cells[0].Text.ToString();
lnk.NavigateUrl = "~/" + e.Item.Cells[0].Text.ToString();
e.Item.Cells[0].Controls.Add(lnk);
lnk.Text = str;
}

If you know any solution for my issue, Please let me know!.




Much Obliged & Thanks A Lot,
Myself




Responses

Author: Ramesh Pedada    12 Aug 2008Member Level: SilverRating:     Points: 4
You can make that column as template column and you can add hyperlink in that. in that case no need to write code in the data bound section.

<asp:TemplateColumn HeaderText="FileName" datafield="FileName">
<ItemTemplate>
<a href="#" "></a>
</ItemTemplate>
</asp:TemplateColumn>


Author: Sidewinder2    12 Aug 2008Member Level: GoldRating:     Points: 1
Thank you !,

I will try it!



Much Obliged & Thanks A Lot,
Myself


Author: Mexi Renjith Mamman    12 Aug 2008Member Level: GoldRating:     Points: 6

You can do like this also:

use a template column
<asp:TemplateColumn>
<asp:LinkButton runat="server" ID="lbtnName" Text="Document Name" CommandName="Name"></asp:LinkButton>
</asp:TemplateColumn>

In the code behind:
protected void dg1_ItemCommand(object source, DataGridCommandEventArgs e)
{
if (e.CommandName == "Name")
{
Response.Redirect("DocDetails.aspx?Name="+e.Item.Cells[0].Text.ToString();
}
}
In the DocDeatils page you can check the queryString and bind the details.

OR

You can bind the grid in the same page itself , in this case Bind the Grid in the Item Command Event after checking the command Name.



Post Reply
You must Sign In to post a response.
Next : Navigation in Gridview
Previous : I want to learn AJAX for ASP.NET 2.0
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

it help desk

Contact Us    Privacy Policy    Terms Of Use