i want to search record in gridview date wise ,Employee wise and Section wise.
datewise and employee my query is working fine but when i apply search on Section then result is not coming as i want ,i created deferent procedure
here is my html code
<table class="auto-style1">
<tr>
<td class="auto-style2">
</td>
<td>
<h1>
Produce Bale Item Wise</h1>
</td>
<td>
</td>
</tr>
<tr>
<td class="auto-style2">
</td>
<td>
<h4>
DateSearch : From
<asp:TextBox ID="txtitempbstart" runat="server" TextMode="DateTimeLocal"></asp:TextBox>
To:
<asp:TextBox ID="txtitempbend" runat="server" TextMode="DateTimeLocal"></asp:TextBox>
<asp:Button ID="btnalbb" runat="server" Text="Search" OnClick="btnpbiw_Click" />
<asp:DropDownList ID="DDworker" runat="server" CssClass="form-control js-example-placeholder-single"
ToolTip="Select ">
</asp:DropDownList>
<asp:DropDownList ID="DDLSec" runat="server">
</asp:DropDownList>
</h4>
</td>
<td>
</td>
</tr>
<tr>
<td class="auto-style2">
</td>
<td>
<div style="height: 500px; width: 720px; overflow: auto;">
<asp:GridView ID="GVallbb" runat="server" OnRowDataBound="GVallbb_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Bale No">
<ItemTemplate>
<asp:Label ID="BalNo" runat="server" Text='<%#Bind("BalNo")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OrderNo">
<ItemTemplate>
<asp:Label ID="OrderNo" runat="server" Text='<%#Bind("OrderNo")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Item Name">
<ItemTemplate>
<asp:Label ID="itemName" runat="server" Text='<%#Bind("Descriptionitem")%>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTotalText" Text="Total" runat="server"></asp:Label></FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</td>
<td>
</td>
</tr>
</table>
here is my c# Code
SqlConnection con = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
txtitempbstart.Text = DateTime.Now.ToString();
txtitempbend.Text = DateTime.Now.ToString();
{
con = new SqlConnection("Data Source=DESKTOP-5PJ76B9;Integrated Security=SSPI;Initial Catalog=SilverProduction;MultipleActiveResultSets=True;");
con.Open();
{
{
con = new SqlConnection("Data Source=DESKTOP-5PJ76B9;Integrated Security=SSPI;Initial Catalog=SilverProduction;MultipleActiveResultSets=True;");
con.Open();
SqlDataAdapter adpwn = new SqlDataAdapter("select * from Worker", con);
DataSet dswn = new DataSet();
adpwn.Fill(dswn);
DDworker.Items.Add(new ListItem("--Select worker--", ""));
DDworker.AppendDataBoundItems = true;
DDworker.DataSource = dswn.Tables[0];
DDworker.DataTextField = "Namworker";
DDworker.DataValueField = "IDwokrer";
DDworker.DataBind();
con.Close();
}
{
con = new SqlConnection("Data Source=DESKTOP-5PJ76B9;Integrated Security=SSPI;Initial Catalog=SilverProduction");
con.Open();
SqlDataAdapter adpbas = new SqlDataAdapter("select * from Sections", con);
DataSet dsbas = new DataSet();
adpbas.Fill(dsbas);
DDLSec.Items.Add(new ListItem("--Select Section--", ""));
DDLSec.AppendDataBoundItems = true;
DDLSec.DataSource = dsbas.Tables[0];
DDLSec.DataTextField = "Secnam";
DDLSec.DataValueField = "SecID";
DDLSec.DataBind();
con.Close();
}
}
}
}
}
protected void btnpbiw_Click(object sender, EventArgs e)
{
con = new SqlConnection("Data Source=DESKTOP-5PJ76B9;Integrated Security=SSPI;Initial Catalog=SilverProduction;MultipleActiveResultSets=True;");
con.Open();
if (DDworker.SelectedValue == "")
{
SqlCommand cmd = new SqlCommand("Searchbaledatewise2");
cmd.Parameters.Add(new SqlParameter("@StartDate", DateTime.Parse(txtitempbstart.Text).ToString("M/d/yyyy h:mm:ss tt", System.Globalization.CultureInfo.InvariantCulture)));
cmd.Parameters.Add(new SqlParameter("@EndDate", DateTime.Parse(txtitempbend.Text).ToString("M/d/yyyy h:mm:ss tt ", System.Globalization.CultureInfo.InvariantCulture)));
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
GVallbb.DataSource = dt;
GVallbb.DataBind();
con.Close();
}
else if (DDworker.SelectedValue != "")
{
SqlCommand cmd = new SqlCommand("Searchbaledatewise");
cmd.Parameters.Add(new SqlParameter("@StartDate", DateTime.Parse(txtitempbstart.Text).ToString("M/d/yyyy h:mm:ss tt", System.Globalization.CultureInfo.InvariantCulture)));
cmd.Parameters.Add(new SqlParameter("@EndDate", DateTime.Parse(txtitempbend.Text).ToString("M/d/yyyy h:mm:ss tt ", System.Globalization.CultureInfo.InvariantCulture)));
cmd.Parameters.Add(new SqlParameter("@workerID", DDworker.SelectedValue));
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
GVallbb.DataSource = dt;
GVallbb.DataBind();
con.Close();
}
if (DDLSec.SelectedValue != "")
{
SqlCommand cmd = new SqlCommand("Searchbaledatewise3");
cmd.Parameters.Add(new SqlParameter("@StartDate", DateTime.Parse(txtitempbstart.Text).ToString("M/d/yyyy h:mm:ss tt", System.Globalization.CultureInfo.InvariantCulture)));
cmd.Parameters.Add(new SqlParameter("@EndDate", DateTime.Parse(txtitempbend.Text).ToString("M/d/yyyy h:mm:ss tt ", System.Globalization.CultureInfo.InvariantCulture)));
cmd.Parameters.Add(new SqlParameter("@workerID", DDworker.SelectedValue));
cmd.Parameters.Add(new SqlParameter("@SecID", DDLSec.SelectedValue));
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
GVallbb.DataSource = dt;
GVallbb.DataBind();
con.Close();
}
}
Decimal TotalValue = 0;
protected void GVallbb_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lbl = (Label)e.Row.FindControl("itemQty");
TotalValue += Convert.ToDecimal(lbl.Text);
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
Label lbl = (Label)e.Row.FindControl("lblTotal");
lbl.Text = TotalValue.ToString();
}
}
here is my store procedure for Section
ALTER PROCEDURE [dbo].[Searchbaledatewise3]
@StartDate Datetime,
@Enddate Datetime,
@workerID int,
@SecID int
AS
BEGIN
SET NOCOUNT ON;
SELECT Probale.Prdno AS BalNo, SalesOrder.OrderNo, ItemMasterFile.Descriptionitem,Probale.prdqty AS QTY,ItemMasterFile.BaleSize, salesorder.Order_Ref_No as Ref_ID,Worker.Namworker as worker,Sections.Secnam As Section,Probale.EntryDate
FROM Probale INNER JOIN
SalesOrder ON SalesOrder.OrderNo = Probale.OrderNo INNER JOIN
ItemMasterFile ON ItemMasterFile.CodeItem = Probale.Codeitem
inner Join Worker on Worker.IDwokrer=Probale.IDwokrer
inner Join Sections on Sections.SecID=ItemMasterFile.SecID
where Convert(DateTime,Probale.EntryDate,103) between @StartDate and @Enddate or (Worker.IDwokrer=@workerID or @workerID IS NULL) and (Sections.SecID=@SecID)
END
or is there any way to hanlde all searching conding in one store procedure please guide thanks