M
Mike
Hello,
I have a gridview that I want to basically convert to behavior like Excel
autofilter. I have created a dropdown list and put it into the header of the
gridview, but I can't seem to reference it correctly. I have been trolling
through the net and ms references for hours but I can't get it straight.
Here is the html code:
<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="datagridtest4.aspx.vb" Inherits="datagridtest4" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="AccessDataSource1">
<Columns>
<asp:TemplateField HeaderText="Vendor" SortExpression="Vendor">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("Vendor") %>'></asp:TextBox>
</EditItemTemplate>
<HeaderTemplate>
<aspropDownList ID="DropDownList1" runat="server"
AutoPostBack="True"
DataSourceID="AccessDataSource1"
DataTextField="Vendor"
DataValueField="VendorID"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</aspropDownList>
<asp:AccessDataSource ID="AccessDataSource1"
runat="server"
DataFile="~/App_Data/courses.mdb"
SelectCommand="SELECT * FROM [tblVendors] ORDER BY
[Vendor]">
</asp:AccessDataSource>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("Vendor") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="BasicCourseName"
HeaderText="BasicCourseName"
SortExpression="BasicCourseName" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/courses.mdb"
SelectCommand="SELECT * FROM
[qryCoursesByVendors]"></asp:AccessDataSource>
</form>
</body>
</html>
I don't know where to attach the code behind the form; on the dropdown list
changed event, or the page load event, or...? I am sorry if this is stupid,
but I can't seem to get it. Here is what I have in the code behind the form:
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs)
Dim ddlVendor As DropDownList
ddlVendor = Me.GridView1.FindControl("DropDownList1")
AccessDataSource1.FilterExpression = "VendorID = " &
ddlVendor.SelectedItem.Text
End Sub
I have also experimented with:
ddlVendor = CType(GridView1.TemplateControl.FindControl("DropDownList1"),
DropDownList)
I get the following error message:
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
Source Error:
Line 36: Dim ddlVendor As DropDownList
Line 37: ddlVendor = Me.GridView1.FindControl("DropDownList1")
Line 38: AccessDataSource1.FilterExpression = "VendorID = " &
ddlVendor.SelectedItem.Text
Line 39: End If
Is there any way to implement this type of thing, or is this a nightmare? I
am a beginning programmer, and I've already spent many days making only
incremental advances.
thanks in advance for your help and support.
mike
I have a gridview that I want to basically convert to behavior like Excel
autofilter. I have created a dropdown list and put it into the header of the
gridview, but I can't seem to reference it correctly. I have been trolling
through the net and ms references for hours but I can't get it straight.
Here is the html code:
<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="datagridtest4.aspx.vb" Inherits="datagridtest4" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="AccessDataSource1">
<Columns>
<asp:TemplateField HeaderText="Vendor" SortExpression="Vendor">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("Vendor") %>'></asp:TextBox>
</EditItemTemplate>
<HeaderTemplate>
<aspropDownList ID="DropDownList1" runat="server"
AutoPostBack="True"
DataSourceID="AccessDataSource1"
DataTextField="Vendor"
DataValueField="VendorID"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</aspropDownList>
<asp:AccessDataSource ID="AccessDataSource1"
runat="server"
DataFile="~/App_Data/courses.mdb"
SelectCommand="SELECT * FROM [tblVendors] ORDER BY
[Vendor]">
</asp:AccessDataSource>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("Vendor") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="BasicCourseName"
HeaderText="BasicCourseName"
SortExpression="BasicCourseName" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/courses.mdb"
SelectCommand="SELECT * FROM
[qryCoursesByVendors]"></asp:AccessDataSource>
</form>
</body>
</html>
I don't know where to attach the code behind the form; on the dropdown list
changed event, or the page load event, or...? I am sorry if this is stupid,
but I can't seem to get it. Here is what I have in the code behind the form:
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs)
Dim ddlVendor As DropDownList
ddlVendor = Me.GridView1.FindControl("DropDownList1")
AccessDataSource1.FilterExpression = "VendorID = " &
ddlVendor.SelectedItem.Text
End Sub
I have also experimented with:
ddlVendor = CType(GridView1.TemplateControl.FindControl("DropDownList1"),
DropDownList)
I get the following error message:
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
Source Error:
Line 36: Dim ddlVendor As DropDownList
Line 37: ddlVendor = Me.GridView1.FindControl("DropDownList1")
Line 38: AccessDataSource1.FilterExpression = "VendorID = " &
ddlVendor.SelectedItem.Text
Line 39: End If
Is there any way to implement this type of thing, or is this a nightmare? I
am a beginning programmer, and I've already spent many days making only
incremental advances.
thanks in advance for your help and support.
mike