Below is the code for Displaying the DropDownLists.
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="bankname" DataValueField="bankname"></asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource2" DataTextField="scheme" DataValueField="scheme">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:tracking %>" SelectCommand="SELECT * FROM [scheme]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:tracking %>" SelectCommand="SELECT * FROM [bank]"></asp:SqlDataSource>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Search" class="btn_green" />
<div class="sh" style="width: 10px;">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3" Visible="False" ForeColor="#333333" CssClass="table table-bordered" onselectedindexchanged="GridView_SelectedIndexChanged">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="id" HeaderText="id" SortExpression="id" InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="loanamount" HeaderText="loanamount" SortExpression="loanamount" />
<asp:BoundField DataField="branch" HeaderText="branch" SortExpression="branch" />
<asp:BoundField DataField="officename" HeaderText="officename" SortExpression="officename" />
<asp:BoundField DataField="schemename" HeaderText="schemename" SortExpression="schemename" />
<asp:BoundField DataField="reciptoffdate" HeaderText="reciptoffdate" SortExpression="reciptoffdate" DataFormatString="{0:dd/MM/yyyy}" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:tracking %>" SelectCommand="SELECT [id], [name], [loanamount], [branch], [officename], [schemename], [reciptoffdate] FROM [transaction] WHERE (([branch] = @branch) AND ([schemename] = @schemename))">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="branch" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="DropDownList2" Name="schemename" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Label ID="Label1" runat="server" Text="" Visible="false"></asp:Label>
Now We will see the code behind it:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView_SelectedIndexChanged(Object sender, EventArgs e)
{
string apid = GridView1.SelectedRow.Cells[1].Text;
Session["appno"] = apid;
Response.Redirect("print.aspx");
}
protected void Button1_Click(object sender, EventArgs e)
{
string query = "select * from [transaction] where schemename='" + DropDownList2.SelectedItem.Text.ToString() + "'and branch='" + DropDownList1.SelectedItem.Text.ToString() + " ' ";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["tracking"].ConnectionString);
SqlCommand cmd = new SqlCommand(query, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
con.Open();
sqlReader=cmd.ExecuteReader();
if (sqlReader.Read())
{
Label1.Visible = false;
GridView1.Visible = true;
}
else
{
Label1.Visible = true;
GridView1.Visible = false;
Label1.Text = "error";
}
con.Close();
}
public SqlDataReader sqlReader { get; set; }
}
This is the grid view when we click on the search button And when we click on the select in the Table We get redirected to an other page which displays all its details.


No comments:
Post a Comment