Hi micah,
HTML
<div>
<asp:TextBox ID="txtSDate" runat="server" />
<asp:DropDownList ID="ddlSbranch" runat="server">
<asp:ListItem Value=" " Text="SELECT" />
<asp:ListItem Value="Reims" Text="Reims" />
<asp:ListItem Value="Münster" Text="Münster" />
<asp:ListItem Value="Rio de Janeiro" Text="Rio de Janeiro" />
<asp:ListItem Value="Lyon" Text="Lyon" />
<asp:ListItem Value="Charleroi" Text="Charleroi" />
<asp:ListItem Value="Bern" Text="Bern" />
<asp:ListItem Value="Genève" Text="Genève" />
<asp:ListItem Value="Resende" Text="Resende" />
<asp:ListItem Value="San Cristóbal" Text="San Cristóbal" />
</asp:DropDownList>
<asp:Button ID="btnSearch" Text="Search" OnClick="btnSSubmit_Click" runat="server" />
</div>
<br />
<div>
<asp:GridView ID="SingleRecord" runat="server" AutoGenerateColumns="False" DataKeyNames="OrderId"
CssClass="table table-striped table-bordered responsive">
<Columns>
<asp:TemplateField HeaderText="OrderId" InsertVisible="False" ItemStyle-Width="120">
<ItemTemplate>
<%# Eval("OrderId")%>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblOrderId" runat="server" Text='<%# Eval("OrderId") %>' />
</EditItemTemplate>
<HeaderStyle />
</asp:TemplateField>
<asp:TemplateField HeaderText="Location" SortExpression="Location" ItemStyle-Width="180">
<EditItemTemplate>
<asp:TextBox ID="txtLocation" runat="server" Text='<%# Bind("ShipCity" ) %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ShipCity") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CustomerId" SortExpression="UserName" ItemStyle-Width="180">
<EditItemTemplate>
<asp:TextBox ID="txtCustomerId" runat="server" Text='<%# Bind("CustomerId" ) %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblCustomerId" runat="server" Text='<%# Bind("CustomerId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OrderDate" SortExpression="OrderDate" ItemStyle-Width="100">
<EditItemTemplate>
<asp:TextBox ID="txtOrderDate" runat="server" Text='<%# Bind("OrderDate" ) %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("OrderDate" ,"{0:MMM dd,yyyy }") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Brand" ItemStyle-Width="130">
<ItemTemplate>
<%# Eval("ShipName")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtBrand" runat="server" Text='<%# Eval("ShipName") %>' />
</EditItemTemplate>
<HeaderStyle />
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.GetData();
}
}
private void GetData()
{
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand("SELECT * FROM Orders", con);
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
SingleRecord.DataSource = dt;
SingleRecord.DataBind();
}
protected void btnSSubmit_Click(object sender, EventArgs e)
{
// txtSDate.Enabled = false;
// ddlSbranch.Enabled = false;
String strConnString = ConfigurationManager.ConnectionStrings["Constring"].ConnectionString;
SqlConnection conne = new SqlConnection(strConnString);
SqlCommand cmdd3 = new SqlCommand();
cmdd3.CommandType = CommandType.StoredProcedure;
cmdd3.CommandText = "OrdersData";
cmdd3.Parameters.AddWithValue("@OrderDate", this.txtSDate.Text.Trim());
cmdd3.Parameters.AddWithValue("@City", this.ddlSbranch.SelectedValue.Trim());
cmdd3.Parameters.AddWithValue("@CompanyUserName", this.User.Identity.Name);
cmdd3.Connection = conne;
try
{
conne.Open();
SingleRecord.EmptyDataText = "No Records Found";
SingleRecord.DataSource = cmdd3.ExecuteReader();
SingleRecord.DataBind();
}
catch (Exception ex)
{
throw ex;
}
//
finally
{
conne.Close();
conne.Dispose();
}
}
SQL
CREATE PROCEDURE OrdersData
@City VARCHAR(20)
,@OrderDate DateTime
,@CompanyUserName VARCHAR(20)=NULL
AS
BEGIN
SET NOCOUNT ON;
SELECT [OrderID]
,[CustomerID]
,[EmployeeID]
,[OrderDate]
,[ShipName]
,[ShipCity]
FROM [Orders]
WHERE (ShipCity =@City OR @City='') AND (OrderDate =@OrderDate OR @OrderDate='')
END
GO
Screenshot