kats9993 says:
write now thier are two columns display Id and pdf display columns but i wnat to diaplay only pdf file columns. i dont want display Id columns .. So plz help me..
1
2
3
4
5
6
7
8
9
10
11
12
|
protected void GridView1_RowDataBound( object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string embed = "<object data=\"{0}{1}\" type=\"application/pdf\" width=\"500px\" height=\"500px\">" ;
embed += "If you are unable to view file, you can download from <a href = \"{0}{1}&download=1\">here</a>" ;
embed += "</object>" ;
int Data = Convert.ToInt32(e.Row.Cells[0].Text);
(e.Row.FindControl( "ltEmbed" ) as Literal).Text = string .Format(embed, ResolveUrl( "~/File.ashx?Id=" ), Data);
}
}
|
Refered your previous Question.
You can do it by two ways. By hidden field it will easy to maintain to get value by name of hidden field instead of finding cell value in code.
1) Remove the BoundField of ID and add Hidenfield with value as Id which will use for File id on RowDataBound. So change in HTML and Code like below.
HTML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="Name" HeaderText="File Name" />
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:HiddenField ID="hfId" runat="server" Value='<%#Eval("Id") %>' />
<asp:Literal ID="ltEmbed" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
C#
string embed = "<object data=\"{0}{1}\" type=\"application/pdf\" width=\"300px\" height=\"200px\">";
embed += "If you are unable to view file, you can download from <a href = \"{0}{1}&download=1\">here</a>";
embed += " or download <a target = \"_blank\" href = \"http://get.adobe.com/reader/\">Adobe PDF Reader</a> to view the file.";
embed += "</object>";
int fileId = Convert.ToInt32((e.Row.FindControl("hfId") as HiddenField).Value);
(e.Row.FindControl("ltEmbed") as Literal).Text = string.Format(embed, ResolveUrl("~/FileCS.ashx?Id="), fileId);
2) You can Add CSS which will Hide the BoundField by assigning class with style: None and apply
<style>
.hide
{
display: none;
}
</style>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="Id" HeaderText="File Id" HeaderStyle-CssClass="hide" ItemStyle-CssClass="hide" />
<asp:BoundField DataField="Name" HeaderText="File Name" />
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Literal ID="ltEmbed" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>