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
|
| Author: Ramesh Pedada 12 Aug 2008 | Member Level: Silver | Rating: 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 2008 | Member Level: Gold | Rating: Points: 1 |
Thank you !,
I will try it!
Much Obliged & Thanks A Lot, Myself
|
| Author: Mexi Renjith Mamman 12 Aug 2008 | Member Level: Gold | Rating: 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.
|