Wednesday, September 8, 2010

Example on how to filter parameters from dropdownlist using sql datasouce and Grid view

by Narendra, .Net Developer

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color: Red">
Example on how to filter parameters from dropdownlist using sql datasouce and Grid view</h2>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:masterConnectionString %>"
SelectCommand="SELECT * FROM [student]"></asp:SqlDataSource>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
DataTextField="name" DataValueField="name" AutoPostBack="True" ForeColor="red"
BackColor="yellow">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:masterConnectionString %>"
SelectCommand="SELECT * FROM [student]" FilterExpression="name='{0}'">
<FilterParameters>
<asp:ControlParameter Name="name" ControlID="DropDownList1" PropertyName="SelectedValue" />
</FilterParameters>
</asp:SqlDataSource>
<br />
<br />
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource2" HeaderStyle-BackColor="HotPink"
HeaderStyle-ForeColor="AntiqueWhite" BorderColor="SaddleBrown"
ForeColor="SeaGreen" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="id" HeaderText="id" SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="dob" HeaderText="dob" SortExpression="dob" />
<asp:BoundField DataField="fees" HeaderText="fees" SortExpression="fees" />
</Columns>
<HeaderStyle BackColor="HotPink" ForeColor="AntiqueWhite"></HeaderStyle>
</asp:GridView>
</div>
</form>
</body>
</html>

0 comments:

Post a Comment

Related Posts with Thumbnails