Chevy Mark Sunderland

Chevy Mark Sunderland

  • NA
  • 188
  • 167.4k

Gridview with Filtering option

Jul 20 2012 2:35 PM
Hello there.
First of all I must say that I am a newbie when it comes to net (C#).

Here is my problem.

I can not populate the DropDownList with ID="ddlName" when select the value in the DropDownList with ID="ddlMatr" and vice versa.

If you have link for similar task, please give it me.
Can you explain any one or any sample code related this.

Your help would be very appreciated.
Thanks in advance for your time and hints.

Cheers.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>Gridview with Filtering option</title>
</head>
<body>
<form id="form1" runat="server">
<div class="GridviewDiv">
<table style="width: 420px" border="0" cellpadding="0" cellspacing="1" class="GridviewTable">
<tr>
<td style="width: 120px;">
Matr
</td>
<td style="width: 130px;">
Name
</td>
<td style="width: 130px;">
EMail
</td>
</tr>
<tr>
<td style="width: 120px;">
<asp:DropDownList ID="ddlMatr" runat="server" DataSourceID="dsMatr" DataValueField="Matr"
AutoPostBack="true" Width="120px" Font-Size="11px" AppendDataBoundItems="true">
<asp:ListItem Text="All" Value="%" />
</asp:DropDownList>
</td>
<td style="width: 130px;">
<asp:DropDownList ID="ddlName" runat="server" DataSourceID="dsName" DataValueField="Name"
AutoPostBack="true" Width="120px" Font-Size="11px" AppendDataBoundItems="true">
<asp:ListItem Text="All" Value="%" />
</asp:DropDownList>
</td>
<td style="width: 130px;">
<asp:DropDownList ID="ddlEMail" runat="server" DataSourceID="dsEMail" DataValueField="EMail"
AutoPostBack="true" Width="120px" Font-Size="11px" AppendDataBoundItems="true">
<asp:ListItem Text="All" Value="%" />
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="5">
<asp:GridView runat="server" ID="gvdetails" ShowHeader="false" AllowPaging="true"
PageSize="10" DataSourceID="dsdetails" AutoGenerateColumns="false" Width="420px"
CssClass="Gridview">
<Columns>
<asp:BoundField DataField="Matr" HeaderText="Matr" ItemStyle-Width="130px" />
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="130px" />
<asp:BoundField DataField="EMail" HeaderText="EMail" ItemStyle-Width="120px" />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
<asp:SqlDataSource ID="dsMatr" runat="server" ConnectionString="<%$ ConnectionStrings:ConnMySQL %>"
ProviderName="<%$ ConnectionStrings:ConnMySQL.ProviderName %>" SelectCommand="Select Matr from tbl_1">
</asp:SqlDataSource>
<asp:SqlDataSource ID="dsName" runat="server" ConnectionString="<%$ ConnectionStrings:ConnMySQL %>"
ProviderName="<%$ ConnectionStrings:ConnMySQL.ProviderName %>" SelectCommand="Select Matr, Name from tbl_1"
FilterExpression=" Matr Like '{0}%'">
<FilterParameters>
<asp:ControlParameter Name="Matr" ControlID="ddlMatr" PropertyName="SelectedValue" />
</FilterParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="dsEMail" runat="server" ConnectionString="<%$ ConnectionStrings:ConnMySQL %>"
ProviderName="<%$ ConnectionStrings:ConnMySQL.ProviderName %>" SelectCommand="Select EMail from tbl_1 WHERE EMail is not null AND email <> ''">
</asp:SqlDataSource>
<asp:SqlDataSource ID="dsdetails" runat="server" ConnectionString="<%$ ConnectionStrings:ConnMySQL %>"
ProviderName="<%$ ConnectionStrings:ConnMySQL.ProviderName %>" SelectCommand="select * from tbl_1"
FilterExpression=" Matr Like '{0}%' and Name Like '{1}%'">
<FilterParameters>
<asp:ControlParameter Name="Matr" ControlID="ddlMatr" PropertyName="SelectedValue" />
<asp:ControlParameter Name="Name" ControlID="ddlName" PropertyName="SelectedValue" />
</FilterParameters>
</asp:SqlDataSource>
</form>
</body>
</html>

Answers (2)