I have my GridView here .. (Automatically generated as WebForm Template)
I want to create a searchbox wherein I can search all the PTAID ..
Here's my codes
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" ShowFooter="True" OnRowCommand="grdSearch_RowCommand" CssClass="table table-bordered table-hovered">
<Columns>
<asp:TemplateField >
<FooterTemplate>
<asp:TextBox ID="text_search" runat="server" CssClass="form-control" />
<asp:Button ID="btnSearch" CommandName="Search" runat="server" Text="Search" />
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField DataField="PTAID" HeaderText="PTAID" SortExpression="PTAID" />
<asp:BoundField DataField="RequestID" HeaderText="RequestID" SortExpression="RequestID" />
<asp:BoundField DataField="RequestDate" HeaderText="RequestDate" SortExpression="RequestDate" />
<asp:BoundField DataField="ProvName" HeaderText="ProvName" SortExpression="ProvName" />
<asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" />
<asp:BoundField DataField="INorOUT" HeaderText="INorOUT" SortExpression="INorOUT" />
<asp:BoundField DataField="Supplier" HeaderText="Supplier" SortExpression="Supplier" />
<asp:BoundField DataField="Customer" HeaderText="Customer" SortExpression="Customer" />
<asp:BoundField DataField="Program" HeaderText="Program" SortExpression="Program" />
<asp:BoundField DataField="IssueDesc" HeaderText="IssueDesc" SortExpression="IssueDesc" />
<asp:BoundField DataField="Chargeable" HeaderText="Chargeable" SortExpression="Chargeable" />
<asp:BoundField DataField="Company" HeaderText="Company" SortExpression="Company" />
</Columns>
</asp:GridView>
How will I make a searchbox ? I tried the one I searched but then i wanted to show the GridView data and the searchbox altogether.
Please try following code, it should work:
<div>
Enter UserName :
<asp:TextBox ID="txtSearch" runat="server" />
<asp:ImageButton ID="btnSearch" text="Search" runat="server"
Style="top: 5px; position: relative; width: 26px;" />
<asp:ImageButton ID="btnClear" text="Clear" runat="server" Style="top: 5px;
position: relative; width: 14px;" /><br />
<br />
</p>
<asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="False" AllowPaging="True"
AllowSorting="True" DataSourceID="dsDetails" Width="540px" CssClass="Gridview" >
<HeaderStyle BackColor="#df5015" />
<Columns>
<asp:BoundField DataField="PTAID" HeaderText="PTAID" SortExpression="PTAID" />
<asp:BoundField DataField="RequestID" HeaderText="RequestID" SortExpression="RequestID" />
<asp:BoundField DataField="RequestDate" HeaderText="RequestDate" SortExpression="RequestDate" />
<asp:BoundField DataField="ProvName" HeaderText="ProvName" SortExpression="ProvName" />
<asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" />
<asp:BoundField DataField="INorOUT" HeaderText="INorOUT" SortExpression="INorOUT" />
<asp:BoundField DataField="Supplier" HeaderText="Supplier" SortExpression="Supplier" />
<asp:BoundField DataField="Customer" HeaderText="Customer" SortExpression="Customer" />
<asp:BoundField DataField="Program" HeaderText="Program" SortExpression="Program" />
<asp:BoundField DataField="IssueDesc" HeaderText="IssueDesc" SortExpression="IssueDesc" />
<asp:BoundField DataField="Chargeable" HeaderText="Chargeable" SortExpression="Chargeable" />
<asp:BoundField DataField="Company" HeaderText="Company" SortExpression="Company" />
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSource ID="dsDetails" runat="server" ConnectionString="<%$ ConnectionStrings:DemoConnectionString %>" SelectCommand="SELECT [name], [address] FROM [stud_info]" FilterExpression="Name LIKE '%{0}%'">
<FilterParameters>
<asp:ControlParameter Name="PTAID" ControlID="txtSearch" PropertyName="Text" />
</FilterParameters>
</asp:SqlDataSource>
Related
I have a GridView table which links to my tblAssets table within SQL Server. I have a "View" hyperlink field which will link to the new page with the AssetID (PK) in the URL. I am wanting to use whichever AssetID is generated in the URL in a SQL View that I have created - I got close whereby clicking on the "View" field will redirect to the page and have the correct URL but will return everything from the SQL View. So I tried to change the SelectCommand but it returned an error.
This is my .aspx code for the GridView:
<form id="frmAssets" runat="server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:AssetManagementConnectionString %>"
SelectCommand="SELECT * FROM [tblAssets]"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="AssetID" DataSourceID="SqlDataSource1" AllowSorting="True" BackColor="White"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4"
Font-Names="Segoe UI" ForeColor="Black" GridLines="Horizontal" style="font-weight: 700" AllowPaging="True" PageSize="20" Font-Size="Small">
<AlternatingRowStyle BorderStyle="None" Font-Overline="False" />
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="AssetID" DataNavigateUrlFormatString="AssetDetails.aspx?AssetID={0}" Text="View" />
<asp:BoundField DataField="Asset_Tag" HeaderText="Asset Tag" SortExpression="Asset_Tag" >
<HeaderStyle Width="100px" />
<ItemStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="Asset_Type" HeaderText="Asset Type" SortExpression="Asset_Type" >
<HeaderStyle Width="200px" />
<ItemStyle Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="Manufacturer" HeaderText="Manufacturer" SortExpression="Manufacturer" >
<HeaderStyle Width="200px" />
<ItemStyle Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" >
<HeaderStyle Width="200px" />
<ItemStyle Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="Serial_Number" HeaderText="Serial_Number" SortExpression="Serial_Number" >
<HeaderStyle Width="300px" />
<ItemStyle Width="300px" />
</asp:BoundField>
<asp:BoundField DataField="UserID" HeaderText="UserID" SortExpression="UserID" >
<HeaderStyle Width="100px" />
<ItemStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="DepartmentID" HeaderText="DepartmentID" SortExpression="DepartmentID" >
<HeaderStyle Width="100px" />
<ItemStyle Width="100px" />
</asp:BoundField>
</Columns>
Apologies for the poor embedding.
This is the .aspx code for the page which it redirects to (I'm assuming I need to change the SelectCommand but can't get it working:
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="Asset Tag" HeaderText="Asset Tag" SortExpression="Asset Tag" />
<asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
<asp:BoundField DataField="Manufacturer" HeaderText="Manufacturer" SortExpression="Manufacturer" />
<asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
<asp:BoundField DataField="Department" HeaderText="Department" SortExpression="Department" />
<asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True" SortExpression="Name" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AssetManagementConnectionString %>" SelectCommand="SELECT * FROM [tblAssets]"></asp:SqlDataSource>
Add SelectParameters from http get query to the detail select query
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:AssetManagementConnectionString %>" SelectCommand="SELECT * FROM [tblAssets] WHERE AssetID = #AssetID">
<SelectParameters>
<asp:QueryStringParameter QueryStringField ="AssetID" Name="AssetID" Type="Int32" DefaultValue="0" />
</SelectParameters>
</asp:SqlDataSource>
I have a dropdown in which I have two options,
a. Selected
b. Not Selected.
I want whenever the user selects any option, the search should filter on that basis. I have a column of Selection in gridview which has both option Selected and Not Selected. The values are coming from the table.
Please see the HTML of dropdown and button for your reference:
<div style="float: left;">
<asp:DropDownList ID="ddlSort" runat="server" AutoPostBack="false" OnSelectedIndexChanged="ddlSort_SelectedIndexChanged">
<asp:ListItem Text="--Select--" Value="1"></asp:ListItem>
<asp:ListItem Text="Selected" Value="2"></asp:ListItem>
<asp:ListItem Text="Not Selected" Value="3"></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnSortSelection" runat="server" Text="Sort Selection" OnClick="btnSortSelection_Click" />
</div>
I tried with the below mentioned code but the page refreshes and the dropdown inside the gridview loses its value. So it did not returns my search result.:-
protected void ddlSort_SelectedIndexChanged(object sender, EventArgs e) {
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultSQLConnectionString"].ConnectionString); //create connection
SqlCommand cmd = new SqlCommand("Select * from Career.Applicant where Selection =#Selected", conn);
cmd.Parameters.AddWithValue("#selection", ddlSort.SelectedValue);
}
I want to stop the dropdownlist values to get postback and also it should work when sorted
Please see the code with Updated Panel:-
<asp:UpdatePanel runat="server" ID="updateapplicants">
<ContentTemplate>
<div style="border: 1px solid #A8A8A8; width: 920px;">
<asp:GridView ID="gv_Applicants" runat="server" AutoGenerateColumns="false" AllowPaging="true" Width="920"
PageSize="5" OnPageIndexChanging="gv_Applicants_PageIndexChanging" OnRowCommand="gv_Applicants_RowCommand"
EmptyDataText="No Applicants Found."
AllowSorting="true"
OnSorting="gv_Applicants_Sorting"
OnRowDataBound="gv_Applicants_RowDataBound" RowStyle-CssClass="a12" AlternatingRowStyle-CssClass="a22" ForeColor="#333333" GridLines="None" CssClass="table_box" HeaderStyle-Height="35px" DataKeyNames="JobId">
<AlternatingRowStyle BackColor="#F0F0F0" />
<Columns>
<asp:BoundField DataField="FirstName" HeaderText="First Name" HeaderStyle-Width="84" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" HeaderStyle-Width="106" />
<asp:BoundField DataField="ContactNumber" HeaderText="Contact" HeaderStyle-Width="98" />
<asp:BoundField DataField="Email" HeaderText="Email" HeaderStyle-Width="150" />
<asp:TemplateField HeaderText="Position" SortExpression="Position" HeaderStyle-Width="107">
<ItemTemplate>
<%# Eval("Job.Position") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Location" SortExpression="Location" HeaderStyle-Width="100">
<ItemTemplate>
<%# Eval("Job.Location") %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="AppliedDate" DataFormatString="{0:MMMM dd, yyyy}" HeaderText="Date of Application" ReadOnly="true" HeaderStyle-Width="121" />
<asp:TemplateField HeaderText="Action" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:LinkButton ID='lnkView' CommandName='v' Text='View' runat='server' CommandArgument='<%# Eval("ApplicantId") %>'></asp:LinkButton>
|
<asp:LinkButton ID='lnkdel' CommandName='d' Text='Delete' runat='server' CommandArgument='<%# Eval("ApplicantId") %>' OnClientClick="return confirm('Are you sure to delete?');"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Selection">
<ItemTemplate>
<asp:DropDownList ID="ddlSelection" runat="server" EnableViewState="true" AutoPostBack="true">
<asp:ListItem Text="None" Value="1"></asp:ListItem>
<asp:ListItem Text="Selected" Value="2"></asp:ListItem>
<asp:ListItem Text="Not Selected" Value="3"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="JobId" HeaderText="Job ID" Visible="false" ReadOnly="true" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#D8DADA" Font-Bold="True" />
<HeaderStyle BackColor="#D8DADA" Font-Bold="True" />
<PagerStyle BackColor="#D8DADA" HorizontalAlign="Center" />
<RowStyle BackColor="white" BorderStyle="Solid" BorderColor="#a8a8a8" BorderWidth="1px" Height="35" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
</div>
<br />
<br />
<div id="divDetails" runat="server" class="force-overflow">
<div class="scrollbar" id="style-1">
<div style="border-left: 1px solid #A8A8A8; border-right: 1px solid #A8A8A8;">
<asp:DetailsView ID="dv_Applicants" HeaderStyle-Font-Bold="true" HeaderStyle-BackColor="#F7E1E1" runat="server" AutoGenerateRows="false" AllowPaging="false"
HeaderText="Applicant Details" OnDataBound="dv_Applicants_DataBound" Width="912px" BackColor="#F0F0F0" BorderStyle="Solid" BorderWidth="1" BorderColor="#F0F0F0"
RowStyle-Height="30" Font-Size="10">
<Fields>
<asp:TemplateField HeaderText="Position" HeaderStyle-CssClass="c_width">
<ItemTemplate>
<%#Eval("Job.Position") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Location" HeaderStyle-CssClass="c_width">
<ItemTemplate>
<%#Eval("Job.Location") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Business Unit" HeaderStyle-CssClass="c_width">
<ItemTemplate>
<%#Eval("Job.BusinessUnit") %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="FirstName" HeaderText="First Name" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="ContactNumber" HeaderText="Contact" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="Email" HeaderText="Email" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="PAN" HeaderText="PAN" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="DOB" DataFormatString="{0:MMMM dd, yyyy}" HeaderText="Date of Birth" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="Graduation" HeaderText="Graduation" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="GradOther" HeaderText="Other" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="GradDate" DataFormatString="{0:MMMM dd, yyyy}" HeaderText="Graduation Date" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="PostGraduation" HeaderText="Post Graduation" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="PGOther" HeaderText="Other" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="PGDate" DataFormatString="{0:MMMM dd, yyyy}" HeaderText="Post Graduation date" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="AnyOtherQual" HeaderText="Any Other Qualification" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="CurrentOrg" HeaderText="Organization" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="CurrentDesignation" HeaderText="Designation" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="CurrentFunctionalDesig" HeaderText="Current Functional Designation" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="CurrentCTC" DataFormatString="{0} lakhs per annum" HeaderText="CTC" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="YrsinCurrentRole" HeaderText="Current Experience" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="TotalExp" HeaderText="Total Experience" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="KeySkills" HeaderText="Skills" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="City" HeaderText="City" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="State" HeaderText="State" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="Country" HeaderText="Country" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:TemplateField HeaderText="Willing to Relocate" ControlStyle-CssClass="c_width" HeaderStyle-CssClass="c_width">
<ItemTemplate>
<%# Convert.ToBoolean(Eval("WillingtoRelocate")) == true ? "Yes" : "No" %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="LocationPreference" HeaderText="Location Preference" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
<asp:BoundField DataField="AppliedDate" DataFormatString="{0:MMMM dd, yyyy}" HeaderText="Date of Application" ReadOnly="true" HeaderStyle-Font-Bold="true" />
<asp:HyperLinkField DataNavigateUrlFields="CVFilePath" Text="View Resume" ControlStyle-ForeColor="White" ControlStyle-CssClass="bg" Target="_blank" />
</Fields>
</asp:DetailsView>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
when i use template in edit mode with out avalidation control ,when user click edit
lins of grid turn to edit mode and page not send eny postback to server. but when i use
edit template with validation contorol ,the page sending postback to server and page is
reloads all content agaian. how can i fix so page will act like first one
<asp:GridView ID="gridProducts" BorderColor="Black" DataSourceID="sourceProducts" DataKeyNames="ProductID" AutoGenerateColumns="false"
AllowPaging="true" PageSize="3" AllowSorting="true" EnablePersistedSelection="true" runat="server">
<HeaderStyle BackColor="Black" ForeColor="White"/>
<RowStyle BackColor="Gray" ForeColor="White" />
<Columns>
<asp:BoundField HeaderText="ID" ReadOnly="true" SortExpression="ProductID" DataField="ProductID" />
<asp:BoundField HeaderText="NAME" SortExpression="ProductName" DataField="ProductName" />
<asp:BoundField HeaderText="ONE UNIT PRICE" DataFormatString="{0:c}" SortExpression="UnitPrice" DataField="UnitPrice" />
<asp:TemplateField HeaderText="STATUS">
<ItemStyle Width="100px" />
<ItemTemplate>
<b>In Srock:</b>
<%#Eval("UnitsInStock")%><br />
<b>On Order:</b>
<%#Eval("UnitsOnOrder")%><br />
<b>Reorder</b>
<%#Eval("ReorderLevel")%>
</ItemTemplate>
<EditItemTemplate>
<b>In Stock:</b><%#Eval("UnitsInStock")%><br />
<b>On Order:</b><%#Eval("UnitsOnOrder")%><br />
<asp:TextBox ID="txtReorder" runat="server" Text='<%# Bind("ReorderLevel") %>' Width="30px"></asp:TextBox>
<asp:RangeValidator ID="rngValidator" MinimumValue="0"
MaximumValue="100" ErrorMessage="Value Out Of Range" ControlToValidate="txtReorder" EnableClientScript="true" Type="Integer" runat="server">
</asp:RangeValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Button" ShowEditButton="true" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="sourceProducts" runat="server"
ConnectionString="<%$ConnectionStrings:Northwind%>"
SelectCommand="SELECT ProductID,ProductName,UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel
FROM Products WHERE CategoryID=#CategoryID"
UpdateCommand="UPDATE Products SET ProductName=#ProductName,UnitPrice=#UnitPrice,
ReorderLevel=#ReorderLevel WHERE ProductID=#ProductID">
<SelectParameters>
<asp:ControlParameter Name="CategoryID" ControlID="gridCategories" PropertyName="SelectedDataKey.Value" />
</SelectParameters>
</asp:SqlDataSource>
I want to show sum of values on header text in grid view.
Code:
.aspx
<asp:GridView ID="gvTrHty" runat="server" AutoGenerateColumns="false" Width="100%"
Style="border: 0px solid #cdcdcd; background-color: #cdcdcd;" border="0" CellSpacing="1"
CellPadding="3" OnSorting="gvTrHty_Sorting" AllowSorting="true">
<Columns>
<asp:TemplateField HeaderText="S.No" ItemStyle-VerticalAlign="Middle" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Employee" DataField="UserFullName" SortExpression="UserFullName" />
<asp:BoundField HeaderText="Course" DataField="CourseName" SortExpression="CourseName" />
<asp:BoundField HeaderText="Duration(Hrs)" DataField="Duration" SortExpression="Duration" />
<asp:BoundField HeaderText="Start Date" DataField="StartDate" DataFormatString="{0:dd-MMM-yyyy}"
SortExpression="StartDate" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" />
<asp:BoundField HeaderText="End Date" DataField="EndDate" DataFormatString="{0:dd-MMM-yyyy}"
SortExpression="EndDate" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" />
<asp:BoundField HeaderText="Result" DataField="RESULT" ItemStyle-HorizontalAlign="Center"
SortExpression="RESULT" ItemStyle-VerticalAlign="Middle" />
<asp:BoundField HeaderText="Year" DataField="Year" ItemStyle-HorizontalAlign="Center"
SortExpression="Year" ItemStyle-VerticalAlign="Middle" />
<asp:BoundField HeaderText="Category" DataField="Category" ItemStyle-HorizontalAlign="Center"
SortExpression="Category" ItemStyle-VerticalAlign="Middle" />
<asp:BoundField HeaderText="Sub Category" DataField="SubCategory" SortExpression="SubCategory" />
</Columns>
<HeaderStyle CssClass="header-link grid-Header DataGridFixedHeader gvHead " />
<RowStyle CssClass="gd_odd_txt gvRow" />
</asp:GridView>
In the below image format I want to get sum of Duration
Any ideas? Thanks in advance
I have a GridView control which displays records depending on the user input in a search textbox, I also have DropDownList to filter search. What I want to do is to display all the records from a table if a user doesnt type any input from the textbox. I've tried putting another table inside the EmptyDataTemplate but it looked a bit cramped. Is there another way?
<td>
Book Reservation<br />
<br />
Search for book title
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="categoryDataSource" DataTextField="name"
DataValueField="categoryid" AppendDataBoundItems="true" >
<asp:ListItem Value="-1" Selected="True">-- Choose a category --</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="categoryDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
SelectCommand="SELECT [categoryid], [name] FROM [TblCategory]">
</asp:SqlDataSource>
<asp:Button ID="Button1" runat="server" Text="Search" />
<br />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="bookid" DataSourceID="bookDataSource" Width="800px" AllowPaging="true"
AllowSorting="true" >
<Columns>
<asp:BoundField DataField="bookid" HeaderText="bookid" ReadOnly="True"
SortExpression="bookid" Visible="false" />
<asp:HyperLinkField DataTextField="booktitle" DataNavigateUrlFields="bookid" HeaderText="Title"
DataNavigateUrlFormatString="Reserving.aspx?bookid={0}" ItemStyle-Width="250px"
SortExpression="booktitle" />
<asp:BoundField DataField="booktitle" HeaderText="Title"
SortExpression="booktitle" Visible="false" />
<asp:BoundField DataField="lastname" HeaderText="Author"
SortExpression="lastname" />
<asp:BoundField DataField="firstname" HeaderText=""
SortExpression="firstname" />
<asp:BoundField DataField="description" HeaderText="Description"
SortExpression="description" />
<asp:BoundField DataField="categoryid" HeaderText="categoryid"
SortExpression="categoryid" Visible="false" />
<asp:BoundField DataField="name" HeaderText="Category"
SortExpression="name" />
<asp:BoundField DataField="dateadded" HeaderText="Dateadded"
SortExpression="dateadded" Visible="false" />
<asp:BoundField DataField="statusid" HeaderText="statusid"
SortExpression="statusid" Visible="false" />
<asp:BoundField DataField="quantity" HeaderText="Quantity"
SortExpression="quantity" />
</Columns>
<EmptyDataTemplate>
<span class="style2">Complete List</span>
<asp:GridView ID="GridView2" runat="server"
AutoGenerateColumns="False" AllowPaging="true" PageSize="8" AllowSorting="true"
DataKeyNames="bookid" DataSourceID="completebookDataSource" Width="800px">
<Columns>
<asp:BoundField DataField="bookid" HeaderText="bookid" ReadOnly="True"
SortExpression="bookid" Visible="false" />
<asp:HyperLinkField DataTextField="booktitle" DataNavigateUrlFields="bookid"
DataNavigateUrlFormatString="Reserving.aspx?bookid={0}" HeaderText="Title"
SortExpression="booktitle" ItemStyle-Width="250px" />
<%--<asp:BoundField DataField="booktitle" HeaderText="Title"
SortExpression="booktitle" />--%>
<asp:BoundField DataField="lastname" HeaderText="Author"
SortExpression="lastname" />
<asp:BoundField DataField="firstname" HeaderText=""
SortExpression="firstname" />
<asp:BoundField DataField="description" HeaderText="Description"
SortExpression="description" />
<asp:BoundField DataField="categoryid" HeaderText="categoryid"
SortExpression="categoryid" Visible="false" />
<asp:BoundField DataField="name" HeaderText="Category"
SortExpression="name" />
<asp:BoundField DataField="dateadded" HeaderText="dateadded"
SortExpression="dateadded" Visible="false" />
<asp:BoundField DataField="statusid" HeaderText="statusid"
SortExpression="statusid" Visible="false" />
<asp:BoundField DataField="quantity" HeaderText="Quantity"
SortExpression="quantity" />
<asp:CheckBoxField DataField="isdeleted" HeaderText="isdeleted"
SortExpression="isdeleted" Visible="false" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="completebookDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
SelectCommand="SELECT dbo.TblBooks.bookid, dbo.TblBooks.booktitle, dbo.TblBooks.lastname, dbo.TblBooks.firstname, dbo.TblBooks.description, dbo.TblBooks.categoryid, dbo.TblBooks.dateadded, dbo.TblBooks.statusid, dbo.TblBooks.quantity, dbo.TblBooks.isdeleted, dbo.TblCategory.name FROM dbo.TblBooks INNER JOIN dbo.TblCategory ON dbo.TblBooks.categoryid = dbo.TblCategory.categoryid ORDER BY dbo.TblBooks.booktitle ASC">
</asp:SqlDataSource>
</EmptyDataTemplate>
</asp:GridView>
<asp:SqlDataSource ID="bookDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
SelectCommand="SELECT dbo.TblBooks.bookid, dbo.TblBooks.booktitle, dbo.TblBooks.lastname, dbo.TblBooks.firstname, dbo.TblBooks.description, dbo.TblBooks.categoryid, dbo.TblBooks.dateadded, dbo.TblBooks.statusid, dbo.TblBooks.quantity, dbo.TblCategory.name FROM dbo.TblBooks INNER JOIN dbo.TblCategory ON dbo.TblBooks.categoryid = dbo.TblCategory.categoryid WHERE (dbo.TblBooks.categoryid = #categoryid) AND (dbo.TblBooks.booktitle LIKE '%' + #booktitle + '%')">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="categoryid"
PropertyName="SelectedValue" Type="Int32" />
<asp:ControlParameter ControlID="TextBox1" Name="booktitle" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<br />
Help would be much appreciated.
Are you looking for this trick?
...WHERE (#Param1 IS NULL OR Field1 >= #Param1)
AND (#Param2 IS NULL OR Field2 LIKE '%' + #Param2 + '%')
You could also change the test to see if a param is equal to an empty string.