Home > Interview Questions > ASP.NET > multi checkbox in radcombbox and get select checkbox Result to gridview

multi checkbox in radcombbox and get select checkbox Result to gridview

by math   on 28/10/2014   Category: ASP.NET   |  Level: Advance   |  Views: 2753    |  Points: 25     |  Starter 


this build page fun
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<style type="text/css">
.style1
{
width: 548px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<p>
<telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
</telerik:RadScriptManager>
<br />
</p>
<p>
<table style="width:100%; height: 97px;">
<tr>
<td>
 </td>
<td class="style1">
 </td>
<td>
<telerik:RadComboBox ID="RadComboBoxEmp1_ID" Runat="server" Height="313px"
HighlightTemplatedItems="True" >
<HeaderTemplate>
<asp:CheckBox ID="CheckBox2" runat="server" Text="ALL" AutoPostBack="True"
oncheckedchanged="CheckBox2_CheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True"
oncheckedchanged="CheckBox2_CheckedChanged"
Text='<%# Eval("EMPL_NAME") %>' />
</ItemTemplate>
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</telerik:RadComboBox>
</td>
</tr>
<tr>
<td>
 </td>
<td class="style1">
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox>
</td>
<td>
 </td>
</tr>
<tr>
<td>
 </td>
<td class="style1">
<asp:TextBox ID="TextBox2" runat="server" Height="132px" TextMode="MultiLine"
Width="297px"></asp:TextBox>
</td>
<td>
<asp:GridView ID="GridViewEmpl" runat="server" AllowPaging="True"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="empl_id">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("EMPL_ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="empl_name">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("EMPL_NAME") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="empl_name_id">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("EMPL_NAME_ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</p>
<p>
 </p>
<p>
 </p>
</asp:Content>


pls the code by vb

1. I have 2 controls radcombobox and gridview
2. Radcombobox databind
Private con As New SqlConnection("Data Source=bma-pc;Initial Catalog=hrdb;Integrated Security=True")


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' RadComboBoxEmp1_ID.AutoPostBack = True


Dim adapter As New SqlDataAdapter("SELECT EMPL_ID, EMPL_ID+' '+FIRST_NAME+' '+ISNULL(SECOND_NAME,' ')+' '+ ISNULL(FAMILY_NAME,' ') as EMPL_NAME FROM HAL_HR_EMPLOYE_BSC_TAP where END_SERVC_FLG LIKE '0' OR END_SERVC_FLG IS NULL order by cast([EMPL_ID]as int) asc ", con)
Dim links As New DataTable()
adapter.Fill(links)

RadComboBoxEmp1_ID.DataTextField = "EMPL_NAME"
RadComboBoxEmp1_ID.DataValueField = "EMPL_ID"
RadComboBoxEmp1_ID.DataSource = links
RadComboBoxEmp1_ID.DataBind()



End Sub


3. Radcombobox I don’t have properties EnableCheckAllItemsCheckBox="true" I create 2 checkbox control in radcombobox template

a. <HeaderTemplate>

<asp:CheckBox ID="CheckBox2" runat="server" Text="ALL" AutoPostBack="True"
oncheckedchanged="CheckBox2_CheckedChanged" />
</HeaderTemplate>
b. <ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True"
AutoPostBack="True"
oncheckedchanged="CheckBox2_CheckedChanged"
Text='<%# Eval("EMPL_NAME") %>' />
</ItemTemplate>
c. Behind code
Protected Sub CheckBox2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

Dim chk As CheckBox = TryCast(sender, CheckBox)

If chk.ID = "CheckBox2" Then
For Each item As RadComboBoxItem In RadComboBoxEmp1_ID.Items
' If item..RowType = DataControlRowType.DataRow Then

item.Controls.OfType(Of CheckBox)().FirstOrDefault().Checked = chk.Checked

' row.Cells(2).Controls.OfType(Of RadComboBox)().FirstOrDefault().Visible = False
' End If
TextBox1.Text += "'" & item.Value & "',"


Next



End If

For Each item As RadComboBoxItem In RadComboBoxEmp1_ID.Items

DirectCast(item.FindControl("CheckBox1"), CheckBox).Checked = chk.Checked
If DirectCast(item.FindControl("CheckBox1"), CheckBox).ID <> "CheckBox1" Then
chk.Checked = False
End If
' chk.Checked = False
' Dim chk As CheckBox = TryCast(sender, CheckBox)
' If chk.Checked = True Then
TextBox2.Text += DirectCast(item.FindControl("CheckBox1"), CheckBox).ID & ", "
'End If
If DirectCast(item.FindControl("CheckBox1"), CheckBox).Checked = True Then
DirectCast(item.FindControl("CheckBox1"), CheckBox).Checked = True
TextBox2.Text += DirectCast(item.FindControl("CheckBox1"), CheckBox).ID & ", "
End If



Next

RadComboBoxEmp1_ID.OpenDropDownOnLoad = True

End Sub




When I dropdownopen radcombobox show select check all object with checkbox CheckBox2 name and when I change the checkbox all it select check all object and remove all select check when I remove
In ItemTemplate but my problem start when I change checkbox in <ItemTemplate> <asp:CheckBox ID="CheckBox1" here when I select item with select check 1 by 1 or remove some select check not work I need help to change select check









4. Gridview I need after select check in radcombobox but the value in
Private Sub BindGrid()
Dim cmd As New SqlCommand("SELECT EMPL_ID, EMPL_ID+' '+FIRST_NAME+' '+ISNULL(SECOND_NAME,' ')+' '+ ISNULL(FAMILY_NAME,' ') as EMPL_NAME FROM HAL_HR_EMPLOYE_BSC_TAP where here after select check how I but the value from radcombobox ")
GridViewEmpl.DataSource = Me.ExecuteQuery(cmd, "SELECT")
GridViewEmpl.DataBind()

to get data in the gridview filtering or find item by radcombobox or create parameter to get select check pls help me what to do


« Is XML case-sensitive?
» drordown list with filtered multiple checkboxs
Post Question  |  Question Home

Recent Posts

User Responses


No response found, be the first to review this question.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts