The webform I am using pulls the data from an AccessDataSourc e to populate the gridview, which has Edit and Delete functions. I have also configured it so that I can insert into the gridview using the footer row.
What I am now trying to do is create two searchable dropdowns in the header of the first two columns (company and reference) that would just return the chosen results, but when the options are clicked, the page just refreshes. Have trawled the internet and various books, but seem unable to find any answer; I think it's the way I am creating the dropdown? Since I've never been able to get a dropdown to filter the gridview.
I am using VB/.NET 2.0 and Visual Studio 2005. Any help as to why my postback isn't working would be fabulous!
The .aspx page:
Expand|Select|Wrap|Line Numbers
- <%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" enableviewstate="true" smartnavigation="false"%>
- <!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 id="Head1" runat="server">
- <title>Project Management</title>
- <style type="text/css">
- #Select1
- {
- height: 16px;
- width: 32px;
- }
- </style>
- </head>
- <body>
- <form id="form1" runat="server">
- <div style="font-family: Arial, Helvetica, sans-serif" >
- <asp:AccessDataSource ID="AccessDataSource1" runat="server"
- ConflictDetection="CompareAllValues" DataFile="~/App_Data/proman.mdb"
- DeleteCommand="DELETE FROM [tbl1] WHERE [pmid] = @pmid"
- InsertCommand="INSERT INTO [tbl1] ([pmcom], [pmref], [pmdate], [pmtime], [pmnotes], [pmclosed], [pmfollowup]) VALUES (?, ?, ?, ?, ?, ?, ?)"
- OldValuesParameterFormatString="original_{0}"
- SelectCommand="SELECT [pmcom], [pmref], [pmdate], [pmtime], [pmnotes], [pmclosed], [pmfollowup], [pmid] FROM [tbl1]"
- UpdateCommand="UPDATE [tbl1] SET [pmcom] = @pmcom, [pmref] = @pmref, [pmdate] = @pmdate, [pmtime] = @pmtime, [pmnotes] = @pmnotes, [pmclosed] = @pmclosed, [pmfollowup] = @pmfollowup WHERE [pmid] = @pmid" >
- <DeleteParameters>
- <asp:Parameter Name="original_pmid" Type="Int32" />
- </DeleteParameters>
- <UpdateParameters>
- <asp:Parameter Name="pmcom" Type="String" />
- <asp:Parameter Name="pmref" Type="String" />
- <asp:Parameter Name="pmdate" Type="DateTime" />
- <asp:Parameter Name="pmtime" Type="DateTime" />
- <asp:Parameter Name="pmnotes" Type="String" />
- <asp:Parameter Name="pmclosed" Type="DateTime" />
- <asp:Parameter Name="pmfollowup" Type="String" />
- <asp:Parameter Name="pmid" Type="Int32" />
- </UpdateParameters>
- <InsertParameters>
- <asp:Parameter Name="column1" Type="String" />
- <asp:Parameter Name="column2" Type="String" />
- <asp:Parameter Name="column3" Type="DateTime" />
- <asp:Parameter Name="column4" Type="DateTime" />
- <asp:Parameter Name="column5" Type="String" />
- <asp:Parameter Name="column6" Type="DateTime" />
- <asp:Parameter Name="column7" Type="String" />
- <asp:Parameter Name="column8" Type="Int32" />
- </InsertParameters>
- </asp:AccessDataSource>
- <asp:AccessDataSource ID="AccessDataSource2" runat="server"
- DataFile="~/App_Data/proman.mdb"
- SelectCommand=" SELECT DISTINCT [pmcom] FROM [tbl1]"></asp:AccessDataSource>
Expand|Select|Wrap|Line Numbers
- <asp:AccessDataSource ID="AccessDataSource3" runat="server"
- DataFile="~/App_Data/proman.mdb"
- SelectCommand="SELECT DISTINCT [pmref] FROM [tbl1]"></asp:AccessDataSource>
- <h1>
- <font color="#49724B">Project Management</font><br />
- <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
- DataKeyNames="pmid" DataSourceID="AccessDataSource1" ShowFooter="True"
- AllowPaging="True" BackColor="White" BorderColor="#336666"
- BorderStyle="Double" BorderWidth="3px" CellPadding="4"
- GridLines="Horizontal" style="font-size: small">
- <FooterStyle BackColor="White" ForeColor="#333333" />
- <RowStyle BackColor="White" ForeColor="#333333" />
- <Columns>
- <asp:TemplateField ShowHeader="False">
- <EditItemTemplate>
- <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update" Font-Bold="True" Font-Underline="False" ForeColor="MediumSeaGreen"></asp:LinkButton>
-
- <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" Font-Bold="True" Font-Underline="False" ForeColor="MediumSeaGreen"></asp:LinkButton>
- </EditItemTemplate>
- <FooterTemplate>
- <asp:LinkButton ID="btnAdd" runat="server" Font-Bold="True" Font-Underline="False"
- ForeColor="#49724B" OnClick="btnAdd_Click">Insert</asp:LinkButton>
- </FooterTemplate>
- <ItemTemplate>
- <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
- CommandName="Edit" Text="Edit" Font-Bold="True" Font-Underline="False"
- ForeColor="#49724B"></asp:LinkButton>
-
- <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
- CommandName="Delete" Text="Delete" Font-Bold="True" Font-Underline="False"
- ForeColor="#49724B"></asp:LinkButton>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField HeaderText="Company" SortExpression="pmcom" >
- <EditItemTemplate>
- <asp:DropDownList ID="DropDownList1" runat="server" Text='<%# Bind("pmcom") %>'>
- <asp:ListItem Value="CEDAR"></asp:ListItem>
- <asp:ListItem Value="EAN"></asp:ListItem>
- <asp:ListItem Value="EFIN"></asp:ListItem>
- <asp:ListItem Value="GBC"></asp:ListItem>
- <asp:ListItem></asp:ListItem>
- </asp:DropDownList>
- </EditItemTemplate>
- <FooterTemplate>
- <asp:DropDownList ID="inspmcom" runat="server" AutoPostBack="False">
- <asp:ListItem Value="CEDAR"></asp:ListItem>
- <asp:ListItem Value="EAN"></asp:ListItem>
- <asp:ListItem Value="EFIN"></asp:ListItem>
- <asp:ListItem Value="GBC"></asp:ListItem>
- <asp:ListItem></asp:ListItem>
- </asp:DropDownList>
- </FooterTemplate>
- <HeaderTemplate>
- <asp:LinkButton ID="pmcomlink" runat="server" ForeColor="White" OnClick="pmcomlink_Click">Company</asp:LinkButton>
- <asp:DropDownList ID="pmcomdrop"
- DataTextField="pmcom"
- AutoPostBack="true"
- OnSelectedIndexChanged="pmcomdrop_IndexChanged"
- OnPreRender="SetValue"
- DataSourceID="AccessDataSource2" runat="server"
- Visible="false"/>
- </HeaderTemplate>
- <ItemTemplate>
- <asp:Label ID="Label1" runat="server" Text='<%# Bind("pmcom") %>'></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
Expand|Select|Wrap|Line Numbers
- <asp:TemplateField HeaderText="Reference" SortExpression="pmref">
- <EditItemTemplate>
- <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("pmref") %>'
- Width="75px"></asp:TextBox>
- </EditItemTemplate>
- <FooterTemplate>
- <asp:TextBox ID="inspmref" runat="server" Width="75px"></asp:TextBox>
- </FooterTemplate>
- <HeaderTemplate>
- <asp:LinkButton ID="pmreflink" runat="server" ForeColor="White" OnClick="pmreflink_Click">Reference</asp:LinkButton>
- <asp:DropDownList ID="pmrefdrop" runat="server" AutoPostBack="True"
- DataSourceID="AccessDataSource3" DataTextField="pmref"
- DataValueField="pmref" CausesValidation="True" Visible="false" OnSelectedIndexChanged="pmrefdrop_IndexChanged">
- </asp:DropDownList>
- </HeaderTemplate>
- <ItemTemplate>
- <asp:Label ID="Label2" runat="server" Text='<%# Bind("pmref") %>'></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField HeaderText="Date" SortExpression="pmdate">
- <EditItemTemplate>
- <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("pmdate") %>'
- Width="65px"></asp:TextBox>
- </EditItemTemplate>
- <FooterTemplate>
- <asp:TextBox ID="inspmdate" runat="server" Width="65px"></asp:TextBox>
- <asp:Button ID="btnCal" runat="server" onclick="btnCal_Click" Text="..."
- Width="29px" Height="21px" />
- </FooterTemplate>
- <ItemTemplate>
- <asp:Label ID="Label3" runat="server" Text='<%# Bind("pmdate", "{0:dd/MM/yy}") %>'></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField HeaderText="Time" SortExpression="pmtime">
- <EditItemTemplate>
- <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("pmtime") %>'
- Width="45px"></asp:TextBox>
- </EditItemTemplate>
- <FooterTemplate>
- <asp:TextBox ID="inspmtime" runat="server" Width="45px"></asp:TextBox>
- </FooterTemplate>
- <ItemTemplate>
- <asp:Label ID="Label4" runat="server" Text='<%# Bind("pmtime", "{0:HH:mm}") %>'></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField HeaderText="Notes" SortExpression="pmnotes">
- <EditItemTemplate>
- <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("pmnotes") %>'></asp:TextBox>
- </EditItemTemplate>
- <FooterTemplate>
- <asp:TextBox ID="inspmnotes" runat="server"></asp:TextBox>
- </FooterTemplate>
- <ItemTemplate>
- <asp:Label ID="Label5" runat="server" Text='<%# Bind("pmnotes") %>'></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
Expand|Select|Wrap|Line Numbers
- <asp:TemplateField HeaderText="Closed" SortExpression="pmclosed">
- <EditItemTemplate>
- <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("pmclosed") %>'
- Width="65px"></asp:TextBox>
- </EditItemTemplate>
- <FooterTemplate>
- <asp:TextBox ID="inspmclosed" runat="server" Width="65px"></asp:TextBox>
- <asp:Button ID="btnCal2" runat="server" onclick="btnCal2_Click" Text="..."
- Width="29px" Height="21px"/>
- </FooterTemplate>
- <ItemTemplate>
- <asp:Label ID="Label6" runat="server" Text='<%# Bind("pmclosed", "{0:dd/MM/yy}") %>'></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField HeaderText="Followup" SortExpression="pmfollowup">
- <EditItemTemplate>
- <asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("pmfollowup") %>'></asp:TextBox>
- </EditItemTemplate>
- <FooterTemplate>
- <asp:TextBox ID="inspmfollowup" runat="server"></asp:TextBox>
- </FooterTemplate>
- <ItemTemplate>
- <asp:Label ID="Label7" runat="server" Text='<%# Bind("pmfollowup") %>'></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField HeaderText="ID" InsertVisible="False" SortExpression="pmid" Visible="False">
- <EditItemTemplate>
- <asp:Label ID="Label1" runat="server" Text='<%# Eval("pmid") %>'></asp:Label>
- </EditItemTemplate>
- <FooterTemplate>
- <asp:TextBox ID="inspmid" runat="server" Width="50px"></asp:TextBox>
- </FooterTemplate>
- <ItemTemplate>
- <asp:Label ID="Label8" runat="server" Text='<%# Bind("pmid") %>'></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
- </Columns>
- <PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
- <SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
- <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
- </asp:GridView>
- </h1>
- </div>
- <center>
- <asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="White"
- Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="180px"
- Width="200px" Visible="False" NextPrevFormat="ShortMonth" BorderWidth="1px">
- <SelectedDayStyle BackColor="#333333" ForeColor="White" />
- <TodayDayStyle BackColor="#CCCCCC" />
- <OtherMonthDayStyle ForeColor="#999999" />
- <NextPrevStyle VerticalAlign="Bottom" Font-Bold="True" Font-Size="8pt"
- ForeColor="#333333" />
- <DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
- <TitleStyle BackColor="White" ForeColor="#333333" Font-Bold="True"
- Font-Size="8pt" BorderColor="Black" BorderWidth="4px" />
- </asp:Calendar>
- <asp:Calendar ID="Calendar2" runat="server" BackColor="White" BorderColor="White"
- Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="180px"
- Width="200px" Visible="False" NextPrevFormat="ShortMonth" BorderWidth="1px">
- <SelectedDayStyle BackColor="#333333" ForeColor="White" />
- <TodayDayStyle BackColor="#CCCCCC" />
- <OtherMonthDayStyle ForeColor="#999999" />
- <NextPrevStyle VerticalAlign="Bottom" Font-Bold="True" Font-Size="8pt"
- ForeColor="#333333" />
- <DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
- <TitleStyle BackColor="White" Font-Bold="True" Font-Size="8pt"
- ForeColor="#333333" BorderColor="Black" BorderWidth="4px" />
- </asp:Calendar>
- </center>
- </form>
- </body>
- </html>
Expand|Select|Wrap|Line Numbers
- Partial Class _Default
- Inherits System.Web.UI.Page
- Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As EventArgs)
- Dim column1 As DropDownList = TryCast(GridView1.FooterRow.FindControl("inspmcom"), DropDownList)
- Dim column2 As TextBox = TryCast(GridView1.FooterRow.FindControl("inspmref"), TextBox)
- Dim column3 As TextBox = TryCast(GridView1.FooterRow.FindControl("inspmdate"), TextBox)
- Dim column4 As TextBox = TryCast(GridView1.FooterRow.FindControl("inspmtime"), TextBox)
- Dim column5 As TextBox = TryCast(GridView1.FooterRow.FindControl("inspmnotes"), TextBox)
- Dim column6 As TextBox = TryCast(GridView1.FooterRow.FindControl("inspmclosed"), TextBox)
- Dim column7 As TextBox = TryCast(GridView1.FooterRow.FindControl("inspmfollowup"), TextBox)
- Dim column8 As TextBox = TryCast(GridView1.FooterRow.FindControl("inspmid"), TextBox)
- 'insert statement. alsi insert into primary key column but insert statement needs to show
- ' values without primary key
- AccessDataSource1.InsertParameters("column1").DefaultValue = column1.SelectedValue
- AccessDataSource1.InsertParameters("column2").DefaultValue = column2.Text
- AccessDataSource1.InsertParameters("column3").DefaultValue = column3.Text
- AccessDataSource1.InsertParameters("column4").DefaultValue = column4.Text
- AccessDataSource1.InsertParameters("column5").DefaultValue = column5.Text
- AccessDataSource1.InsertParameters("column6").DefaultValue = column6.Text
- AccessDataSource1.InsertParameters("column7").DefaultValue = column7.Text
- AccessDataSource1.InsertParameters("column8").DefaultValue = column8.Text
- AccessDataSource1.Insert()
- End Sub
- Protected Sub inspmdate_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
- Handles GridView1.DataBound
- Dim inspmdate As TextBox = TryCast(GridView1.FooterRow.FindControl("inspmdate"), TextBox)
- If inspmdate IsNot Nothing Then
- inspmdate.Text = DateTime.Today.ToString("dd/MM/yy")
- End If
- Dim inspmtime As TextBox = TryCast(GridView1.FooterRow.FindControl("inspmtime"), TextBox)
- If inspmtime IsNot Nothing Then
- inspmtime.Text = DateTime.Now.ToString("HH:mm")
- End If
- Dim inspmclosed As TextBox = TryCast(GridView1.FooterRow.FindControl("inspmclosed"), TextBox)
- If inspmclosed IsNot Nothing Then
- inspmclosed.Text = DateTime.Today.ToString("dd/MM/yy")
- End If
- End Sub
- Protected Sub btnCal_Click(ByVal sender As Object, ByVal e As System.EventArgs)
- Dim inspmdate As TextBox = TryCast(GridView1.FooterRow.FindControl("inspmdate"), TextBox)
- Dim Calendar1 As Calendar = TryCast(form1.FindControl("Calendar1"), Calendar)
- Try
- If inspmdate.Text.Trim() <> "" Then
- Calendar1.SelectedDate = Convert.ToDateTime(inspmdate.Text)
- End If
- Catch
- End Try
- 'shows the calendar...
- Calendar1.Visible = True
- End Sub
- Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
- Dim inspmdate As TextBox = TryCast(GridView1.FooterRow.FindControl("inspmdate"), TextBox)
- Dim Calendar1 As Calendar = TryCast(form1.FindControl("Calendar1"), Calendar)
- '...displays the date in the textbox...
- inspmdate.Text = Calendar1.SelectedDate.ToString()
- '...and hides the calendar again
- Calendar1.Visible = False
- End Sub
- Protected Sub btnCal2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
- Dim inspmclosed As TextBox = TryCast(GridView1.FooterRow.FindControl("inspmclosed"), TextBox)
- Dim Calendar2 As Calendar = TryCast(form1.FindControl("Calendar2"), Calendar)
- Try
- If inspmclosed.Text.Trim() <> "" Then
- Calendar2.SelectedDate = Convert.ToDateTime(inspmclosed.Text)
- End If
- Catch
- End Try
- 'shows the calendar...
- Calendar2.Visible = True
- End Sub
- Protected Sub Calendar2_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar2.SelectionChanged
- Dim inspmclosed As TextBox = TryCast(GridView1.FooterRow.FindControl("inspmclosed"), TextBox)
- Dim Calendar2 As Calendar = TryCast(form1.FindControl("Calendar2"), Calendar)
- '...displays the date in the textbox...
- inspmclosed.Text = Calendar2.SelectedDate.ToString()
- '...and hides the calendar again
- Calendar2.Visible = False
- End Sub
- Protected Sub pmcomlink_Click(ByVal sender As Object, ByVal e As System.EventArgs)
- Dim pmcomlink As LinkButton = TryCast(GridView1.HeaderRow.FindControl("pmcomlink"), LinkButton)
- Dim pmcomdrop As DropDownList = TryCast(GridView1.HeaderRow.FindControl("pmcomdrop"), DropDownList)
- 'shows dropdown when linkbutton clicked
- pmcomdrop.Visible = True
- pmcomlink.Visible = False
- End Sub
- Protected Sub pmreflink_Click(ByVal sender As Object, ByVal e As System.EventArgs)
- Dim pmreflink As LinkButton = TryCast(GridView1.HeaderRow.FindControl("pmreflink"), LinkButton)
- Dim pmrefdrop As DropDownList = TryCast(GridView1.HeaderRow.FindControl("pmrefdrop"), DropDownList)
- 'shows dropdown when link button clicked
- pmrefdrop.Visible = True
- pmreflink.Visible = False
- End Sub
- Protected Sub pmcomdrop_IndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
- Dim pmcomlink As LinkButton = TryCast(GridView1.HeaderRow.FindControl("pmcomlink"), LinkButton)
- Dim pmcomdrop As DropDownList = TryCast(GridView1.HeaderRow.FindControl("pmcomdrop"), DropDownList)
- ' hides dropdown when a company is selected and show the linkbutton
- pmcomdrop.Visible = False
- pmcomlink.Visible = True
- End Sub
- Protected Sub pmrefdrop_IndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
- Dim pmreflink As LinkButton = TryCast(GridView1.HeaderRow.FindControl("pmreflink"), LinkButton)
- Dim pmrefdrop As DropDownList = TryCast(GridView1.HeaderRow.FindControl("pmrefdrop"), DropDownList)
- ' hide the dropdown when a reference is selected and show the link button
- pmrefdrop.Visible = False
- pmreflink.Visible = True
- End Sub
- Protected Sub SetValue(ByVal sender As Object, ByVal e As EventArgs)
- End Sub
- End Class