Hyperlink url for an asp.net gridview column - asp.net

I have a gridview that returns values from a directory path such as :
<table width="40%" border="0" style="margin-left:auto; margin-right:auto;">
<tr>
<td align="center">
<asp:GridView ID="gvFileList" runat="server" AutoGenerateColumns="false" AllowSorting="true">
<columns>
<asp:boundfield datafield="Name" headertext="File Name"/>
<asp:boundfield datafield="Extension" headertext="File Type"/>
<asp:boundfield datafield="Length" headertext="Length"/>
<asp:boundfield datafield="LastCreateTime" headertext="Date"/>
</columns>
</asp:GridView>
</td>
</tr>
</table>
How can I get the values under the "Name" column to have a url similar to "javascript:OpenSecure('abcd.doc') ?
Update:
Given the HTML code below, I am unable to see the hyperlink in the Name field.
<asp:GridView ID="gvInvoiceList" runat="server" AutoGenerateColumns="false" AllowSorting="true">
<columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate><asp:Hyperlink ID="acctInvoiceRpt" NavigateUrl='<%# SetNavigateUrl(Eval("Name")) %>' runat="server"></asp:Hyperlink><%#Eval("Name")%></ItemTemplate>
</asp:TemplateField>
<asp:boundfield datafield="Extension" headertext="File Type"/>

Convert Name field to <ItemTemplate> and try adding a hyperlink
<asp:HyperLink ID="hplName" runat="server" NavigateUrl='<%# "javascript:OpenSecure(''' + Eval("Name") ''') %>' Text='<%# Eval("Name") %>'/>

You would need a custom column for that:
http://msdn.microsoft.com/en-us/library/ms228046.aspx

Related

How to use 2 gridview cell values column to build a hyper link

I have a gridview. I need to build a hyperlink in one column with the value from a different one and its own value. So for example the URL would be something.com/column1value/column2value.
I have the System and theregion hyperlinked via a TemplateField in there respective column. It is in column 2 that i want to build the url based on the value in column1
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SQL" Class='table table-hover' BorderStyle="None" BorderColor="White" GridLines="None" UseAccessibleHeader="False" ShowFooter="True" ShowHeaderWhenEmpty="True" EnableTheming="False">
<Columns>
<asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
<asp:TemplateField HeaderText="System" SortExpression="System">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("System") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("System", "http://evemaps.dotlan.net/system/{0}/") %>' Target="_blank" Text='<%# Eval("System", "{0}") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Region" SortExpression="Region">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Region") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Region", "http://evemaps.dotlan.net/Map/{0}/") %>' Target="_blank" Text='<%# Eval("Region", "{0}") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Owner" HeaderText="Owner" SortExpression="Owner" />
<asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" />
<asp:TemplateField HeaderText="EvE Time" SortExpression="EvE Time">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("[EvE Time]") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="EvETimeLB" runat="server" Text='<%# Bind("[EvE Time]") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle Font-Bold="True" />
</asp:GridView>
Using Eval is not restricted to the column you are using it in. You can use all the columns in an ItemTemplate.
<asp:HyperLink ID="HyperLink1" runat="server" Target="_blank"
NavigateUrl='<%# string.Format("something.com/{0}/{1}", Eval("column1"), Eval("column2")) %>'
Text='<%# string.Format("something.com/{0}/{1}", Eval("column1"), Eval("column2")) %>'>
</asp:HyperLink>

How may I calculate the difference between Registered DateTime and DateTime.now in a gridview?

I want to calculate the difference between Registered DateTime(is in a database) and DateTime.now in a gridview, But get an error. How may I calculate the difference between those times? When I use (Eval("RegDtTime")-DateTime.Now, get this error: operator '-' is not defined for types 'Object' and 'Date'. How should I calculate the difference?
<asp:GridView
ID="GridView1"
runat="server"
AllowSorting="True"
AutoGenerateColumns="False"
DataKeyNames="ID"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="ID"
HeaderText="ID"
ReadOnly="True"
SortExpression="ID" />
<asp:BoundField DataField="RegDtTime"
HeaderText="RegDtTime"
SortExpression="RegDtTime" />
<asp:TemplateField>
<ItemTemplate>
<div>
<asp:LinkButton ID="LinkButton1"
runat="server"
onclick="LinkButton1_Click"
Text='<%# Bind("ID") %>'></asp:LinkButton>
</div>
<div>
RegDateTime:
<asp:Label ID="Label3"
runat="server"
Text='<%# Bind("RegDtTime") %>'></asp:Label>
</div>
<div>
DateTimeNow:
<asp:Label ID="Label4"
runat="server"
Text='<%# DateTime.Now %>'></asp:Label>
</div>
<div>
Passed:
<asp:Label ID="Label5"
runat="server"
Text='<%# (Eval("RegDtTime")-DateTime.Now %>'></asp:Label>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

How to make the Header static in Gridview scroll?

here I'm trying to make a scroll-able Grid View, which I did using the overflow, but the problem is, I want to make the Header section static, allowing only the content to be scrolled, here's my code:
<div class="BodyDiv" style="overflow: auto; height: 200px">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<table width="1024px">
<tr>
<td align="center">
<table width="980px">
<tr>
<td>
<asp:Panel ID="PanelDGV" runat="server" Height="250" ScrollBars="None" Width="515">
<asp:GridView ID="DGV" runat="server" AutoGenerateColumns="False" GridLines="None" AllowPaging="true" PageSize="50" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt">
<Columns>
<asp:BoundField DataField="ProjectCode" HeaderText="Project Code" />
<asp:BoundField DataField="ProjectName" HeaderText="Project Name" />
<asp:ButtonField ButtonType="Image" ImageUrl="../Support/Image/Edit.png" ItemStyle-HorizontalAlign="Center"
CommandName="CmdSearch" HeaderText="Edit">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:ButtonField>
</Columns>
<PagerStyle CssClass="pgr"></PagerStyle>
<AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
</asp:GridView>
</asp:Panel>
</td>
</tr>
</table>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
is there anyway to do it? thank you.
<script src="../Scripts/ScrollableGridPlugin.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$('#<%=Grd.ClientID %>').Scrollable();
}
)
You can download this js file from below url
http://code.google.com/p/dev-acuaman/source/browse/trunk/PyproduceEstad%C3%ACstica/EstadisticaProduce/Scripts/ScrollableGridPlugin.js?r=79
<asp:GridView ID="Grd" runat="server" Width="100%" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Country">
<ItemTemplate>
<asp:Label ID="lbl" runat="server" Text='<%# Eval("CountryName") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Enter Shipping Charge">
<ItemTemplate>
<asp:TextBox ID="txt" runat="server" Text='<%# Eval("charge") %>'></asp:TextBox>
<asp:CompareValidator ID="CompareValidator2" runat="server" ControlToValidate="txt"
ValidationGroup="txt" SetFocusOnError="true" Operator="DataTypeCheck" Type="Double"
ErrorMessage="Country Wise Shipping Charge must be number!">*</asp:CompareValidator>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" Width="160px" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Enter No Of Days">
<ItemTemplate>
<asp:TextBox ID="txt1" runat="server" Text='<%# Eval("days") %>'></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="txt"
ValidationGroup="txt1" SetFocusOnError="true" Operator="DataTypeCheck" Type="Integer"
ErrorMessage="No Of Days must be number!">*</asp:CompareValidator>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" Width="160px" VerticalAlign="Middle" />
</asp:TemplateField>
</Columns>
</asp:GridView>

Header On TemplateField In GridView

How to create Header "Full Name" in GridView when I am creating "TemplateField" with hyperlinks ? For example I want these rows in TemplateField to have header "Full Name".
<asp:GridView ID="CustomersGridView" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("FirstName") + " " + Eval("LastName") %>'
NavigateUrl="CarTest.aspx" > </asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Use the header template:
<Columns>
<asp:TemplateField>
<ItemTemplate>
....................
</ItemTemplate>
<HeaderTemplate>
Full Name
</HeaderTemplate>
</asp:TemplateField>
</Columns>
For more information, read.
<asp:GridView ID="CustomersGridView" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:TemplateField HeaderText="Full Name">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("FirstName") + " " + Eval("LastName") %>'
NavigateUrl="CarTest.aspx" > </asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<div class="table-responsive">
<asp:GridView ID="grdDisCategry" runat="server" CssClass="table table-small-font table-bordered table-striped" Font-Size="Small"
EmptyDataRowStyle-ForeColor="#cc0000" HeaderStyle-Font-Size="10" HeaderStyle-Font-Names="Arial"
AutoGenerateColumns="False" EmptyDataText="No Record Found" HeaderStyle-ForeColor="#990000">
<Columns>
<asp:TemplateField HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<HeaderTemplate>
<asp:TextBox ID="txtMonthsDays" runat="server" class="form-control input-sm m-bot15"
Font-Bold="true" Text='<%#Bind("MonthsDays") %>'></asp:TextBox>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtMonthDays" runat="server" class="form-control input-sm m-bot15"
Font-Bold="true" Text='<%#Bind("MonthDays") %>'></asp:TextBox>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" Width="80px" />
</asp:TemplateField>
</Columns>
<HeaderStyle HorizontalAlign="Justify" VerticalAlign="Top"
Font-Bold="true" />
<RowStyle Font-Size="Small" Height="1" ForeColor="#000000" Font-Italic="true" />
</asp:GridView>

How to set bootstrap style into pager Gridview ASP.Net correctly

I have a gridview and want to implement bootstrap into that gridview, I had been successfull with Header and RowItem, but failed in Pager Grid view.
here's my code :
<asp:GridView ID="GridNews" runat="server" AllowPaging="True" PageSize="2" onpageindexchanging="GridNews_PageIndexChanging"
CssClass="table table-hover table-striped table-condensed" GridLines="None"
AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="news_id" HeaderText="ID" Visible="false" />
<asp:BoundField DataField="date" HeaderText="Date" ItemStyle-Width="50%" />
<asp:TemplateField HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" HeaderText="Title" ItemStyle-HorizontalAlign="Center" >
<ItemTemplate>
<asp:HyperLink ID="LinkEvents" runat="server" Target="_blank" navigateUrl='<%# "EventsDetail.aspx?choice=investor&ev=" + Eval("news_id") %>' Text='<%# Eval("title") %>'>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
Is there i Missed something?
Please help me, thanks

Resources