Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want Grid view Filtered values based on Radio button group.
I tried with some code but not working. sql queries are i am unable to write properly.

Table is:
Profile_RbnFilter
Columns are:
ID, ProfileRbnName

C#
protected void rbnSearchby_SelectedIndexChanged(object sender, EventArgs e)
    {
        string Filter = RbnFilter.SelectedValue.ToString();
        if (RbnFilter.SelectedValue == "10")
        {
            Filter = "select a.SID as ProfileID,a.StaffName as Name,b.Designation,a.Staffqualification as Qualification,a.Uploadphoto as ImageUrl,case a.Status when '1' then 'Active' when '2' then 'InActive' end as Status,convert(varchar(12),a.date,101) as Date from Adding_New_Staff a join Dental_Designation b on a.StaffDesignation=b.Did order by a.sid";
            RadiobuttonList(Filter);
        }
        else if (RbnFilter.SelectedValue == "11")
        {
            Filter = "select a.SID as ProfileID,a.StaffName as Name,b.Designation,a.Staffqualification as Qualification,a.Uploadphoto as ImageUrl,case a.Status when '1' then 'Active' when '2' then 'InActive' end as Status,convert(varchar(12),a.date,101) as Date from Adding_New_Staff a join Dental_Designation b on a.StaffDesignation=b.Did order by a.sid";
            RadiobuttonList(Filter);

        }

        else if (RbnFilter.SelectedValue == "12")
        {
            Filter = "select a.SID as ProfileID,a.StaffName as Name,b.Designation,a.Staffqualification as Qualification,a.Uploadphoto as ImageUrl,case a.Status when '1' then 'Active' when '2' then 'InActive' end as Status,convert(varchar(12),a.date,101) as Date from Adding_New_Staff a join Dental_Designation b on a.StaffDesignation=b.Did order by a.sid";
            RadiobuttonList(Filter);
        }


        else if (RbnFilter.SelectedValue == "13")
        {
            Filter = "select a.SID as ProfileID,a.StaffName as Name,b.Designation,a.Staffqualification as Qualification,a.Uploadphoto as ImageUrl,case a.Status when '1' then 'Active' when '2' then 'InActive' end as Status,convert(varchar(12),a.date,101) as Date from Adding_New_Staff a join Dental_Designation b on a.StaffDesignation=b.Did order by a.sid";
            RadiobuttonList(Filter);
        }
        else if (RbnFilter.SelectedValue == "14")
        {
            Filter = "select a.SID as ProfileID,a.StaffName as Name,b.Designation,a.Staffqualification as Qualification,a.Uploadphoto as ImageUrl,case a.Status when '1' then 'Active' when '2' then 'InActive' end as Status,convert(varchar(12),a.date,101) as Date from Adding_New_Staff a join Dental_Designation b on a.StaffDesignation=b.Did order by a.sid";
            RadiobuttonList(Filter);
        }



ASP.NET
[<span style="font-size: 14px; font-weight: normal;">
                <asp:RadioButtonList ID="RbnFilter" runat="server" 
                RepeatDirection="Horizontal" OnSelectedIndexChanged="rbnSearchby_SelectedIndexChanged"
                    RepeatLayout="Flow" AutoPostBack="True">
                    <asp:ListItem Text="All" Value="10" Selected="true" />
                    <asp:ListItem Text="Doctors" Value="11" />
                    <asp:ListItem Text="Dental Hygienist & Assistants" Value="12" />
                    <asp:ListItem Text="Nurses" Value="13" />
                    <asp:ListItem Text="Front Office" Value="14" />
                </asp:RadioButtonList>
            </span>]
        </h1>
    </div>
    <div>
    <asp:GridView ID="GridProfile" runat="server" AutoGenerateColumns="False" 
            Width="100%" ShowHeaderWhenEmpty="True" class="Grid">
    <Columns>
    <asp:TemplateField HeaderText="Profile ID">
    <ItemTemplate>
        <asp:Label ID="lblProfileID" runat="server" Text='<%# Eval("ProfileID") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Name">
    <ItemTemplate>
        <asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Designation">
    <ItemTemplate>
        <asp:Label ID="lblDesignation" runat="server" Text='<%# Eval("Designation") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Qualification">
    <ItemTemplate>
        <asp:Label ID="lblQualification" runat="server" Text='<%# Eval("Qualification") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Image Url">
    <ItemTemplate>
        <asp:Label ID="lblImageUrl" runat="server" Text='<%# Eval("ImageUrl") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
   <asp:TemplateField HeaderText="Status">
    <ItemTemplate>
        <asp:Label ID="lblStatus" runat="server" Text='<%# Eval("Status") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
     <asp:TemplateField HeaderText="Date">
    <ItemTemplate>
        <asp:Label ID="lbldate" runat="server" Text='<%# Eval("Date") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>

    </Columns>
    </asp:GridView>
Posted
Comments
Rajesh waran 12-Dec-14 2:53am    
So what output you are getting ? and tell us what is your expecting output? also share your complete table design.All queries are looking similar,where you are passing RbnFilter value?
Tomas Takac 12-Dec-14 3:17am    
What's with all the if-else in the filter logic? All the queries are the same or am I missing something? You probably want to use the selected value in the query.
CP_vicky 12-Dec-14 3:43am    
I am missing the Radio button selected values.
Now it is fine

Filter = "select a.SID as ProfileID,a.StaffName as Name,b.Designation,a.Staffqualification as Qualification,a.Uploadphoto as ImageUrl,case a.Status when '1' then 'Active' when '2' then 'InActive' end as Status,convert(varchar(12),a.date,101) as Date from Adding_New_Staff a join Dental_Designation b on a.StaffDesignation=b.Did where a.StaffDesignation='" + RbnFilter.SelectedValue + "' order by a.sid";
Rajesh waran 12-Dec-14 4:34am    
Please do not pass values like this.Try to use parameterised query.

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