Click here to Skip to main content
14,970,403 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i do multi select check list when i run the code it doesnt gave me any data

What I have tried:

ASP.NET
<pre><%@ Page Title="" Language="C#" MasterPageFile="~/User.Master" AutoEventWireup="true" CodeBehind="SearchInEmployeeAtt.aspx.cs" Inherits="Mypro.SearchInEmployeeAtt" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <div  class=" container">


      <h3>Advanced Attendance Filter</h3>



      <div class="row">


                    <div class="col-lg-3 col-md-3 col-xs-12 col-sm-12" style="padding-top:25px" >
                           <div class="form-group">
<asp:LinkButton ID="SrcBtn" OnClick="SrcBtn_Click" runat="server" CssClass="btn btn-small  btn-danger"> Search</asp:LinkButton>                     </div>
                               </div>

      </div>

      <div>
     
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <asp:UpdatePanel ID="updatepanel1" runat="server">

            <ContentTemplate>
                <div class="row">
                    <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
              <div class="form-group row">
    <label for="staticEmail" class=" col-form-label">Date From </label>
 
        <asp:TextBox ID="TxtDate" runat="server"  TextMode="Date" CssClass="form-control" ></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator5" CssClass="text-danger" runat="server" ErrorMessage="Required !" ControlToValidate="TxtDate" ></asp:RequiredFieldValidator>

   
  </div>
        </div>
                    <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
              <div class="form-group row">
    <label for="staticEmail" class=" col-form-label">Date To </label>
 
        <asp:TextBox ID="TxtTo" runat="server"  TextMode="Date" CssClass="form-control" ></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" CssClass="text-danger" runat="server" ErrorMessage="Required !" ControlToValidate="TxtTo" ></asp:RequiredFieldValidator>

   
  </div>
        </div>
                    <div class="col-lg-3 col-md-3 col-xs-12 col-sm-12">
                         <div class="form-group row">
                                 <label for="inputPassword" class=" col-form-label">Please Choose Status Name</label>

                        <asp:TextBox ID="TextBox1" runat="server" AutoCompleteType="Disabled" CssClass="form-control" AutoPostBack="true" ></asp:TextBox>
                                                <asp:TextBox ID="TextBox2" runat="server" AutoCompleteType="Disabled" CssClass="form-control" AutoPostBack="true" Visible="true"></asp:TextBox>

                        <ajaxToolkit:PopupControlExtender ID="TextBox1_PopupControlExtender" runat="server"
                    Enabled="True" ExtenderControlID="" TargetControlID="TextBox1" 
                    PopupControlID="Panel1" >
                </ajaxToolkit:PopupControlExtender>
                 <asp:Panel ID="Panel1" runat="server" Height="140px" Width="170px" BorderStyle="Solid" BorderWidth="3px" Direction="LeftToRight" ScrollBars="Auto" BackColor="beige" Style="display: none">
 <asp:CheckBox ID="chkAll" Text="Select All" runat="server"  OnCheckedChanged="chkAll_CheckedChanged" AutoPostBack = "true" /> 
                     <asp:CheckBoxList ID="CheckBoxList1" runat="server"  AutoPostBack="True" OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged"></asp:CheckBoxList>
                </asp:Panel>
                    </div>
</div>

                    <div class="col-lg-3 col-md-3 col-xs-12 col-sm-12">
                         <div class="form-group row">
                                 <label for="inputPassword" class=" col-form-label">Please Choose Region Name</label>

                        <asp:TextBox ID="TextBox3" runat="server" AutoCompleteType="Disabled" CssClass="form-control" AutoPostBack="true" ></asp:TextBox>
                                                <asp:TextBox ID="TextBox4" runat="server" AutoCompleteType="Disabled" CssClass="form-control" AutoPostBack="true" Visible="true"></asp:TextBox>

                        <ajaxToolkit:PopupControlExtender ID="PopupControlExtender1" runat="server"
                    Enabled="True" ExtenderControlID="" TargetControlID="TextBox3" 
                    PopupControlID="Panel2" >
                </ajaxToolkit:PopupControlExtender>
                 <asp:Panel ID="Panel2" runat="server" Height="140px" Width="170px" BorderStyle="Solid" BorderWidth="3px" Direction="LeftToRight" ScrollBars="Auto" BackColor="beige" Style="display: none">
 <asp:CheckBox ID="Checkall" Text="Select All" runat="server"   OnCheckedChanged="Checkall_CheckedChanged" AutoPostBack = "true" /> 
                     <asp:CheckBoxList ID="CheckBoxList2" runat="server"  AutoPostBack="True"  OnSelectedIndexChanged="CheckBoxList2_SelectedIndexChanged"></asp:CheckBoxList>
                </asp:Panel>
                    </div>
</div>



                      






                </div>
                

                


                
               
            </ContentTemplate>

        </asp:UpdatePanel>
    </div>


<div class="row">
               
                    <div class="col-lg-12 col-md-12 col-xs-12 col-sm-12">

                <asp:Panel ID="Panel3" runat="server" ScrollBars="Both" >
                    
        <asp:GridView ID="GrdData" runat="server" CellPadding="4" CssClass="table table-responsive table-striped " ForeColor="#333333" GridLines="None" AllowPaging="True"    OnPageIndexChanging="GrdData_PageIndexChanging"        >
                            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                            <EditRowStyle BackColor="#999999" />
                            <FooterStyle BackColor="#4B0082" Font-Bold="True" ForeColor="White" />
                            <HeaderStyle BackColor="#4B0082" Font-Bold="True" ForeColor="White"  />
                            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                            <SortedAscendingCellStyle BackColor="#E9E7E2" />
                            <SortedAscendingHeaderStyle BackColor="#506C8C" />
                            <SortedDescendingCellStyle BackColor="#FFFDF8" />
                            <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
              <EditRowStyle BackColor="WindowFrame"  />
                             <SelectedRowStyle BackColor="WindowFrame" /> 
                        </asp:GridView>
                    </asp:Panel>
           
            </div>
            </div>
      
      </div>
    
    
   
   
</asp:Content>

SQL
<pre>alter PROCEDURE  [dbo].[BIND_ATTENDANCE_ADVANCED_FILTER]
@AttendanceDate date,
@DateTo date,
@AttendanceStatus nvarchar(max)

AS
BEGIN
	
	
	select RegionName,BranchName,AttendanceID,DATENAME(weekday, AttendanceDate) as Day_Name,CONVERT(VARCHAR(10),AttendanceDate,101) as AttendanceDate,ShiftFrom,ShiftTo,StatusName from TblAttendance
inner join TblBranch on TblAttendance.BranchID=TblBranch.BranchID
inner join TblStatus on TblAttendance.AttendanceStatus=TblStatus.StatusID
inner join TBLRegion on TblAttendance.RegionID=TBLRegion.RegionID
where AttendanceDate>=@AttendanceDate and AttendanceDate<=@DateTo and  StatusName in(''+@AttendanceStatus+'')  and StatusBalance<=0
order by TblAttendance.RegionID,TblAttendance.BranchID asc 

END
C#
public DataTable BindattendanceAdvancedFilter(BusinessObject_Layer.BO_Layer objbo)
     {

         SqlParameter[] param = new SqlParameter[3];
         param[0] = new SqlParameter("@AttendanceDate", SqlDbType.Date)
         {
             Value = objbo.AttendanceDate
         };

         param[1] = new SqlParameter("@DateTo", SqlDbType.Date)
         {
             Value = objbo.Dateto
         };
         param[2] = new SqlParameter("@AttendanceStatus", SqlDbType.NVarChar,1000)
         {
             Value = objbo.StatusAttendanceFilter
         };



         Dal.Open();
         DataTable dt = new DataTable();
         dt = Dal.SelectData("BIND_ATTENDANCE_ADVANCED_FILTER", param);
         return dt;
     }
C#
<pre> protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
        {


            string StatusName = "";
            string StaTusValues = "";
            for (int i = 0; i < CheckBoxList1.Items.Count; i++)
            {
                if (CheckBoxList1.Items[i].Selected)
                {
                    StatusName += "'" + CheckBoxList1.Items[i].Text + "',";
                    StaTusValues += "'" + CheckBoxList1.Items[i].Value + "',";
                }
            }
            TextBox1.Text =  StatusName.Remove(StatusName.Length - 1, 1).Substring(1);
            TextBox2.Text = StaTusValues.Remove(StaTusValues.Length - 1, 1); 









        }
C#
<pre>protected void chkAll_CheckedChanged(object sender, EventArgs e)
        {

            foreach (ListItem item in CheckBoxList1.Items)
            {
                if (chkAll.Checked==true)
                {
                    string StatusName = "";
                    string StaTusValues = "";
                    for (int i = 0; i < CheckBoxList1.Items.Count; i++)
                    {
                        item.Selected = chkAll.Checked;
                        StatusName += "'" + CheckBoxList1.Items[i].Text + "',";
                        StaTusValues += "'" + CheckBoxList1.Items[i].Value+ "',";

                    }
                    TextBox1.Text = StatusName.Remove(StatusName.Length - 1, 1).Substring(1) ;
                    TextBox2.Text =StaTusValues.Remove(StaTusValues.Length - 1, 1) ;
                }else if (chkAll.Checked == false)
                {
                    TextBox1.Text = "";
                    TextBox2.Text = "";
                    item.Selected = false;
                }
              



            }



        }
C#
<pre>protected void chkAll_CheckedChanged(object sender, EventArgs e)
        {

            foreach (ListItem item in CheckBoxList1.Items)
            {
                if (chkAll.Checked==true)
                {
                    string StatusName = "";
                    string StaTusValues = "";
                    for (int i = 0; i < CheckBoxList1.Items.Count; i++)
                    {
                        item.Selected = chkAll.Checked;
                        StatusName += "'" + CheckBoxList1.Items[i].Text + "',";
                        StaTusValues += "'" + CheckBoxList1.Items[i].Value+ "',";

                    }
                    TextBox1.Text = StatusName.Remove(StatusName.Length - 1, 1).Substring(1) ;
                    TextBox2.Text =StaTusValues.Remove(StaTusValues.Length - 1, 1) ;
                }else if (chkAll.Checked == false)
                {
                    TextBox1.Text = "";
                    TextBox2.Text = "";
                    item.Selected = false;
                }
              



            }



        }
C#
private void BinDattendance()
  {



      BusinessObject_Layer.BO_Layer objbo = new BusinessObject_Layer.BO_Layer();
      objbo.AttendanceDate = Convert.ToDateTime(TxtDate.Text);
      objbo.Dateto = Convert.ToDateTime(TxtTo.Text);
      objbo.StatusAttendanceFilter =TextBox1.Text;
      //objbo.RegionNameFilter = TextBox3.Text;
      DataTable dt = BSS.BindattendanceAdvancedFilter(objbo);

      GrdData.DataSource = dt;
      GrdData.DataBind();


  }



  protected void SrcBtn_Click(object sender, EventArgs e)
  {
      BinDattendance();
  }
Posted
Updated 26-Apr-21 0:13am
v2
Comments
SeanChupas 23-Apr-21 14:54pm
   
What can we do to help?
Barthinia 23-Apr-21 15:00pm
   
something wrong in the code i dont pass textbox1.text as parameter it dont five me any results
SeanChupas 23-Apr-21 15:24pm
   
There's too much code there for me to try and dig through it. All you should have to do is debug it and track down what is going on.

1 solution

Quote:
SQL
alter PROCEDURE  [dbo].[BIND_ATTENDANCE_ADVANCED_FILTER]
@AttendanceDate date,
@DateTo date,
@AttendanceStatus nvarchar(max)

AS
BEGIN
	
	
	select RegionName,BranchName,AttendanceID,DATENAME(weekday, AttendanceDate) as Day_Name,CONVERT(VARCHAR(10),AttendanceDate,101) as AttendanceDate,ShiftFrom,ShiftTo,StatusName from TblAttendance
inner join TblBranch on TblAttendance.BranchID=TblBranch.BranchID
inner join TblStatus on TblAttendance.AttendanceStatus=TblStatus.StatusID
inner join TBLRegion on TblAttendance.RegionID=TBLRegion.RegionID
where AttendanceDate>=@AttendanceDate and AttendanceDate<=@DateTo and  ^__highlight]StatusName in(''+@AttendanceStatus+'')[/highlight__^  and StatusBalance<=0
order by TblAttendance.RegionID,TblAttendance.BranchID asc 

END
Looks like you are trying to pass multiple values in a single parameter. That's not going to work with the IN clause - it will be looking for records where the StatusName is precisely equal to the string you've passed in.

If you're using SQL Server 2016 or later, you can split the comma-separated list of values using the built-in STRING_SPLIT function[^]:
SQL
And StatusName In (SELECT value FROM STRING_SPLIT(@AttendanceStatus, ','))
If you're using an earlier version, Google will find you a suitable replacement function. For example:
Tally OH! An Improved SQL 8K “CSV Splitter” Function – SQLServerCentral[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900