Ok here is my deal. i have a "Report" page from my inventory. currently the gridview is tied into a SQLdatasource that pulls in the whole Inventory which is fine. here is what im trying to accomplish:
I want the page to load with the entire inventory as it is, but i want the option to change what the grid shows to only show equipment from a specific location.
at the top of the page i added a dropdownlist and tied that to another SQLdatasource for the locations so i can select a specific location, what i want is the gridview to change to show only what was selected.
here is the page code. can anyone help me out with this?
at the top of the page i added a dropdownlist and tied that to another SQLdatasource for the locations so i can select a specific location, what i want is the gridview to change to show only what was selected.
In your SqlDataSource you can set up the SelectParameter and within that you can add a ControlParameter to filter your gridview based from the dropdownlist value. Check this post for example:http://forums.asp.net/p/1279387/2442872.aspx#2442872
I did that, problem is when the page loads the gridview is now empty until i select a location from the dropdown list. im trying to figure out how to have the page load will all locations equipment displaying and when i select a location from the dropdown
list then it will only show equipment from that location. i put in a list item with a -1 value that is there by default how do i tell the select command that if it = -1 to display all?
thank you for that link - it will be very useful. now when you say set your Handle Clause to fire up the even im not too sure what that means. im still having issues and i think it is in my SelectCommand
now when you say set your Handle Clause to fire up the even im not too sure what that means
I meant something like this:
Protected Sub SqlDataSource1_Selecting(sender As Object, e As SqlDataSourceSelectingEventArgs) Handles SqlDataSource1.Selecting
SqlDataSource1.SelectParameters.Clear()
End Sub
mcnitt89
im still having issues and i think it is in my SelectCommand
mcnitt89
Member
19 Points
100 Posts
Gridview ideas
Feb 05, 2013 10:34 PM|LINK
Ok here is my deal. i have a "Report" page from my inventory. currently the gridview is tied into a SQLdatasource that pulls in the whole Inventory which is fine. here is what im trying to accomplish:
I want the page to load with the entire inventory as it is, but i want the option to change what the grid shows to only show equipment from a specific location.
at the top of the page i added a dropdownlist and tied that to another SQLdatasource for the locations so i can select a specific location, what i want is the gridview to change to show only what was selected.
here is the page code. can anyone help me out with this?
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="RepInv.aspx.vb" Inherits="_2._0.RepInv" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <style type="text/css"> .style1 { width: 1%; } .style2 { height: 38px; } .style3 { height: 16px; font-family: Arial, Helvetica, sans-serif; font-size: small; color: #FFFFFF; } .style4 { text-decoration: none; } .style5 { color: #000000; } .style6 { } .style7 { width: 37px; height: 16px; } .style8 { width: 421px; font-family: Arial, Helvetica, sans-serif; font-size: x-small; height: 16px; text-align: right; } .style9 { height: 16px; width: 143px; } .style10 { height: 30px; } .style11 { height: 80px; font-family: Arial, Helvetica, sans-serif; font-size: x-small; } .style12 { height: 16px; } </style> </head> <body> <form id="form1" runat="server"> <div style="text-align: center"> <br /> <br /> <br /> <table align="center" class="style1" style="border: thin solid #0066CC"> <tr> <td bgcolor="#EFF3FB" class="style2" colspan="3" style="font-family: Arial, Helvetica, sans-serif; font-size: xx-large"> CTi</td> </tr> <tr> <td bgcolor="#0066CC" class="style3" colspan="3"> COURT TECHNOLOGY iNVENTORY REPORT</td> </tr> <tr> <td class="style7" style="text-align: left; font-family: Arial, Helvetica, sans-serif; font-size: x-small"> <a class="style4" href="Default1.aspx"><span class="style5">< BACK</span></a></td> <td class="style8"> SORT BY LOCATION: <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True" DataSourceID="sdssortby" DataTextField="LOCATION" DataValueField="LOCATION" Height="22px" Width="176px" AutoPostBack="True"> <asp:ListItem>--Select--</asp:ListItem> </asp:DropDownList> </td> <td class="style9" style="text-align: right; font-family: Arial, Helvetica, sans-serif; font-size: x-small"> ITEMS PER PAGE: <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"> <asp:ListItem>10</asp:ListItem> <asp:ListItem>50</asp:ListItem> <asp:ListItem>100</asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <td class="style6" colspan="3"> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="DEVICE_NAME" DataSourceID="sdsinv" EnableModelValidation="True" Font-Size="Small" ForeColor="#333333" style="text-align: left" Width="832px" Font-Names="Arial"> <AlternatingRowStyle BackColor="White" /> <Columns> <asp:BoundField DataField="DEVICE_NAME" HeaderText="DEVICE" ReadOnly="True" SortExpression="DEVICE_NAME" /> <asp:BoundField DataField="DEVICE_TYPE" HeaderText="TYPE" SortExpression="DEVICE_TYPE" /> <asp:BoundField DataField="MANUFACTURER" HeaderText="MAN" SortExpression="MANUFACTURER" /> <asp:BoundField DataField="MODEL" HeaderText="MODEL" SortExpression="MODEL" /> <asp:BoundField DataField="SERIAL_NUMBER" HeaderText="SN#" SortExpression="SERIAL_NUMBER" /> <asp:BoundField DataField="ASSET_NUMBER" HeaderText="ASSET#" SortExpression="ASSET_NUMBER" /> <asp:BoundField DataField="LOCATION" HeaderText="LOCATION" SortExpression="LOCATION" /> <asp:BoundField DataField="OS_VERSION" HeaderText="OS" SortExpression="OS_VERSION" /> <asp:BoundField DataField="STATUS" HeaderText="STATUS" SortExpression="STATUS" /> <asp:BoundField DataField="NOTES" HeaderText="NOTES" SortExpression="NOTES" /> </Columns> <EditRowStyle BackColor="#2461BF" /> <FooterStyle BackColor="#0066CC" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#0066CC" Font-Bold="True" Font-Size="X-Small" ForeColor="White" /> <PagerStyle BackColor="#EFF3FB" Font-Bold="True" ForeColor="#0066CC" HorizontalAlign="Center" /> <RowStyle BackColor="#EFF3FB" /> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> </asp:GridView> </td> </tr> <tr> <td bgcolor="#EFF3FB" class="style11" colspan="3"> - EXPORT TO CSV FILE -<br /> <br /> <asp:Button ID="Button1" runat="server" Text="Export" /> </td> </tr> <tr> <td bgcolor="#0066CC" class="style12" colspan="3"> </td> </tr> </table> <br /> <asp:SqlDataSource ID="sdsinv" runat="server" ConnectionString="<%$ ConnectionStrings:NetworkInventoryConnectionString %>" SelectCommand="SELECT [DEVICE_NAME], [DEVICE_TYPE], [MANUFACTURER], [MODEL], [SERIAL_NUMBER], [ASSET_NUMBER], [LOCATION], [OS_VERSION], [STATUS], [NOTES] FROM [MainDeviceList]"> </asp:SqlDataSource> <asp:SqlDataSource ID="sdssortby" runat="server" ConnectionString="<%$ ConnectionStrings:NetworkInventoryConnectionString %>" SelectCommand="SELECT [LOCATION] FROM [Location]"></asp:SqlDataSource> </div> </form> </body> </html> <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="RepInv.aspx.vb" Inherits="_2._0.RepInv" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <style type="text/css"> .style1 { width: 1%; } .style2 { height: 38px; } .style3 { height: 16px; font-family: Arial, Helvetica, sans-serif; font-size: small; color: #FFFFFF; } .style4 { text-decoration: none; } .style5 { color: #000000; } .style6 { } .style7 { width: 37px; height: 16px; } .style8 { width: 421px; font-family: Arial, Helvetica, sans-serif; font-size: x-small; height: 16px; text-align: right; } .style9 { height: 16px; width: 143px; } .style10 { height: 30px; } .style11 { height: 80px; font-family: Arial, Helvetica, sans-serif; font-size: x-small; } .style12 { height: 16px; } </style> </head> <body> <form id="form1" runat="server"> <div style="text-align: center"> <br /> <br /> <br /> <table align="center" class="style1" style="border: thin solid #0066CC"> <tr> <td bgcolor="#EFF3FB" class="style2" colspan="3" style="font-family: Arial, Helvetica, sans-serif; font-size: xx-large"> CTi</td> </tr> <tr> <td bgcolor="#0066CC" class="style3" colspan="3"> COURT TECHNOLOGY iNVENTORY REPORT</td> </tr> <tr> <td class="style7" style="text-align: left; font-family: Arial, Helvetica, sans-serif; font-size: x-small"> <a class="style4" href="Default1.aspx"><span class="style5">< BACK</span></a></td> <td class="style8"> SORT BY LOCATION: <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True" DataSourceID="sdssortby" DataTextField="LOCATION" DataValueField="LOCATION" Height="22px" Width="176px" AutoPostBack="True"> <asp:ListItem>--Select--</asp:ListItem> </asp:DropDownList> </td> <td class="style9" style="text-align: right; font-family: Arial, Helvetica, sans-serif; font-size: x-small"> ITEMS PER PAGE: <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"> <asp:ListItem>10</asp:ListItem> <asp:ListItem>50</asp:ListItem> <asp:ListItem>100</asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <td class="style6" colspan="3"> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="DEVICE_NAME" DataSourceID="sdsinv" EnableModelValidation="True" Font-Size="Small" ForeColor="#333333" style="text-align: left" Width="832px" Font-Names="Arial"> <AlternatingRowStyle BackColor="White" /> <Columns> <asp:BoundField DataField="DEVICE_NAME" HeaderText="DEVICE" ReadOnly="True" SortExpression="DEVICE_NAME" /> <asp:BoundField DataField="DEVICE_TYPE" HeaderText="TYPE" SortExpression="DEVICE_TYPE" /> <asp:BoundField DataField="MANUFACTURER" HeaderText="MAN" SortExpression="MANUFACTURER" /> <asp:BoundField DataField="MODEL" HeaderText="MODEL" SortExpression="MODEL" /> <asp:BoundField DataField="SERIAL_NUMBER" HeaderText="SN#" SortExpression="SERIAL_NUMBER" /> <asp:BoundField DataField="ASSET_NUMBER" HeaderText="ASSET#" SortExpression="ASSET_NUMBER" /> <asp:BoundField DataField="LOCATION" HeaderText="LOCATION" SortExpression="LOCATION" /> <asp:BoundField DataField="OS_VERSION" HeaderText="OS" SortExpression="OS_VERSION" /> <asp:BoundField DataField="STATUS" HeaderText="STATUS" SortExpression="STATUS" /> <asp:BoundField DataField="NOTES" HeaderText="NOTES" SortExpression="NOTES" /> </Columns> <EditRowStyle BackColor="#2461BF" /> <FooterStyle BackColor="#0066CC" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#0066CC" Font-Bold="True" Font-Size="X-Small" ForeColor="White" /> <PagerStyle BackColor="#EFF3FB" Font-Bold="True" ForeColor="#0066CC" HorizontalAlign="Center" /> <RowStyle BackColor="#EFF3FB" /> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> </asp:GridView> </td> </tr> <tr> <td bgcolor="#EFF3FB" class="style11" colspan="3"> - EXPORT TO CSV FILE -<br /> <br /> <asp:Button ID="Button1" runat="server" Text="Export" /> </td> </tr> <tr> <td bgcolor="#0066CC" class="style12" colspan="3"> </td> </tr> </table> <br /> <asp:SqlDataSource ID="sdsinv" runat="server" ConnectionString="<%$ ConnectionStrings:NetworkInventoryConnectionString %>" SelectCommand="SELECT [DEVICE_NAME], [DEVICE_TYPE], [MANUFACTURER], [MODEL], [SERIAL_NUMBER], [ASSET_NUMBER], [LOCATION], [OS_VERSION], [STATUS], [NOTES] FROM [MainDeviceList]"> </asp:SqlDataSource> <asp:SqlDataSource ID="sdssortby" runat="server" ConnectionString="<%$ ConnectionStrings:NetworkInventoryConnectionString %>" SelectCommand="SELECT [LOCATION] FROM [Location]"></asp:SqlDataSource> </div> </form> </body> </html>vinz
All-Star
126946 Points
17922 Posts
MVP
Re: Gridview ideas
Feb 06, 2013 11:41 AM|LINK
In your SqlDataSource you can set up the SelectParameter and within that you can add a ControlParameter to filter your gridview based from the dropdownlist value. Check this post for example:http://forums.asp.net/p/1279387/2442872.aspx#2442872
You may also read on: Using Parameters with SqlDataSource Control
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
mcnitt89
Member
19 Points
100 Posts
Re: Gridview ideas
Feb 06, 2013 01:20 PM|LINK
So i added this:
<SelectParameters> <asp:ControlParameter ControlID="DropDownList1" Name="LOCATION" PropertyName="SelectedValue" type="String" /> </SelectParameters>im missing something though, and im not sure what it is.
vinz
All-Star
126946 Points
17922 Posts
MVP
Re: Gridview ideas
Feb 06, 2013 01:23 PM|LINK
You also need to change your Select statement to accept the parameter you set like:
SELECT field1,field2... FROM TableName WHERE Location =@Location
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
mcnitt89
Member
19 Points
100 Posts
Re: Gridview ideas
Feb 06, 2013 01:48 PM|LINK
I did that, problem is when the page loads the gridview is now empty until i select a location from the dropdown list. im trying to figure out how to have the page load will all locations equipment displaying and when i select a location from the dropdown list then it will only show equipment from that location. i put in a list item with a -1 value that is there by default how do i tell the select command that if it = -1 to display all?
vinz
All-Star
126946 Points
17922 Posts
MVP
Re: Gridview ideas
Feb 06, 2013 02:15 PM|LINK
You can clear the parameter in your select statement. You can handle the Selecting event do this:
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e) { SqlDataSource1.SelectParameters.Clear(); }You may also want to take a look at this post: http://peterkellner.net/2006/10/14/showallingridviewfromddl/
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
mcnitt89
Member
19 Points
100 Posts
Re: Gridview ideas
Feb 06, 2013 02:17 PM|LINK
what would that look like for a vb backend? that command above is in c# right?
vinz
All-Star
126946 Points
17922 Posts
MVP
Re: Gridview ideas
Feb 06, 2013 02:20 PM|LINK
Right. You can try it like this in VB:
PS: You may want to set your Handle Clause to fire up the event
For future reference you can use this tool to convert C# to VB.NET codes or vise versa: http://www.developerfusion.com/tools/convert/csharp-to-vb/
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
mcnitt89
Member
19 Points
100 Posts
Re: Gridview ideas
Feb 06, 2013 02:27 PM|LINK
thank you for that link - it will be very useful. now when you say set your Handle Clause to fire up the even im not too sure what that means. im still having issues and i think it is in my SelectCommand
vinz
All-Star
126946 Points
17922 Posts
MVP
Re: Gridview ideas
Feb 06, 2013 02:34 PM|LINK
I meant something like this:
Protected Sub SqlDataSource1_Selecting(sender As Object, e As SqlDataSourceSelectingEventArgs) Handles SqlDataSource1.Selecting SqlDataSource1.SelectParameters.Clear() End SubWhat's the issue? Are you getting error?
MessageBox Controls for WebForms | Blog | Twitter | Linkedin