Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

How to run update command based all checked check boxes in dropdownlist

$
0
0

hi,

I have used telerik radcombox box with checkboxes in asp data grid. Rad combox have some values.

All I want to update the checked items of rad combobox in database of each row on single button click.

Here is the screenshot:

ASPX CODE:

<asp:DataGrid ID="DG_SKULayout" runat="server" AutoGenerateColumns="False" Width="100%"
                    AllowSorting="True" AllowPaging="True" CellPadding="3" CellSpacing="0" CssClass="Control_Table"
                    PageSize="20" ShowFooter="true" DataKeyField="attribute_id"><AlternatingItemStyle CssClass="Grid_Alternate_Item" VerticalAlign="Top"></AlternatingItemStyle><ItemStyle CssClass="Grid_Item" VerticalAlign="Top"></ItemStyle><HeaderStyle Wrap="False" CssClass="Control_Header"></HeaderStyle><Columns><asp:TemplateColumn HeaderText="Include"><ItemStyle Width="200" /><ItemTemplate><asp:CheckBox ID="is_include" Checked='<%# IIf(Eval("is_sku_include") = "1", "True","False" )%>'
                                    runat="server" /></ItemTemplate></asp:TemplateColumn><asp:TemplateColumn HeaderText="Attribute Name"><ItemStyle Width="200" /><ItemTemplate><asp:Label ID="lbl_Attribute_Name_sku" Text='<%#Eval("name")%>' runat="server"> </asp:Label></ItemTemplate></asp:TemplateColumn><asp:TemplateColumn HeaderText="Prefix"><ItemStyle Width="200" /><ItemTemplate><asp:TextBox ID="txt_sku_prefix" runat="server" Text='<%#Eval("sku_prefix") %>'></asp:TextBox></ItemTemplate></asp:TemplateColumn><asp:TemplateColumn HeaderText="Suffix"><ItemStyle Width="200" /><ItemTemplate><asp:TextBox ID="txt_sku_suffix" runat="server" Text='<%#Eval("sku_sufix") %>'></asp:TextBox></ItemTemplate></asp:TemplateColumn><asp:TemplateColumn HeaderText="Hide"><ItemStyle Width="200" /><ItemTemplate ><telerik:RadComboBox ID="RadComboBox1" runat="server" CheckBoxes="true"   
                                    Width="300"></telerik:RadComboBox></ItemTemplate></asp:TemplateColumn></Columns><PagerStyle HorizontalAlign="Right" CssClass="Paging" Mode="NumericPages"></PagerStyle></asp:DataGrid>

Code Behind:

   Private Sub BindAttributeAssingmentGrid()

            Dim dt As New DataTable

            dt = SqlHelper.ExecuteDatatable("SELECT ISNULL(A.attribute_id, 0) AS attribute_id,ISNULL(A.name, '') AS name,ISNULL(A.is_mandatory, 0) AS is_mandatory FROM pc_attributes A ORDER BY A.Name")

            Me.DG_AttributeAssingment.DataSource = dt
            Me.DG_AttributeAssingment.DataBind()

            dt.Dispose()

        End Sub

        Private Sub BindSKULayoutGrid()

            Dim dt As New DataTable

            dt = SqlHelper.ExecuteDatatable("SELECT ISNULL(A.name, '') AS name,ISNULL(A.is_attribute, 0) AS is_attribute,ISNULL(A.sku_prefix, '') AS sku_prefix,ISNULL(A.sku_sufix, '') AS sku_sufix,ISNULL(A.title_prefix, '') AS title_prefix,ISNULL(A.title_sufix, '') AS title_sufix,ISNULL(A.is_sku_include, 0) AS is_sku_include,ISNULL(A.is_title_include, 0) AS is_title_include,ISNULL(A.is_title_include, 0) AS is_title_include,ISNULL(A.is_title_include, 0) AS is_title_include,ISNULL(A.attribute_id, 0) AS attribute_id FROM pc_attributes A")

            Me.DG_SKULayout.DataSource = dt
            Me.DG_SKULayout.DataBind()

            dt.Dispose()

        End Sub
        Protected Sub DG_SKULayout_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DG_SKULayout.ItemDataBound
            If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
                Dim attr_id As Integer = DG_SKULayout.DataKeys(e.Item.ItemIndex)
                'Response.Write(attr_id)
                Dim dt_atribvalues As New DataTable
                dt_atribvalues = SqlHelper.ExecuteDatatable("Select ISNULL(A.attribute_value_id, 0) AS attribute_value_id, ISNULL(A.attribute_id, 0) AS attribute_id, ISNULL(A.name, '') AS name, ISNULL(A.is_hidden_sku, 0) AS is_hidden_sku,ISNULL(A.is_hidden_title, 0) AS is_hidden_title from pc_attribute_values A where attribute_id=" & attr_id)
                'Dim ddl As RadComboBox = CType(e.Item.Cells(4).FindControl("RadComboBox1"), RadComboBox)
                Dim ddl As RadComboBox = CType(e.Item.FindControl("RadComboBox1"), RadComboBox)
                ' Response.Write(dt_atribvalues.Rows.Count)
                ddl.DataSource = dt_atribvalues
                ddl.DataTextField = "name"
                ddl.DataValueField = "attribute_value_id"
                ddl.DataBind()
            End If
        End Sub

        Private Sub ShowCheckedItems()
            Dim str As String
            For i As Integer = 0 To DG_SKULayout.Items.Count - 1
                If DG_SKULayout.Items(i).ItemType = ListItemType.AlternatingItem Or DG_SKULayout.Items(i).ItemType = ListItemType.Item Then
                    'Dim attr_id As Integer = DG_SKULayout.DataKeys(i)
                    Dim combobox As New RadComboBox
                    Dim ddl As RadComboBox = CType(DG_SKULayout.Items(i).FindControl("RadComboBox1"), RadComboBox)
                    For Each li As ListItem In ddl.Items
                        If li.Selected Then
                            Dim attr_value_id = li.Value
                            str = SqlHelper.ExecuteScalar("Update pc_attribute_values set is_hidden_sku = 1 where attribute_value_id=" & attr_value_id)
                            'Response.Write("Update pc_attribute_values set is_hidden_sku = 1 where attribute_value_id=" & attr_value_id)
                        End If
                    Next
                End If

            Next
            'Dim sb As New StringBuilder()
            'Dim ComboBox As New RadComboBox
            'Dim collection As IList(Of RadComboBoxItem) = ComboBox.CheckedItems

            'Dim dt_atribvalues As New DataTable
            ''dt_atribvalues = SqlHelper.ExecuteDatatable("Select ISNULL(A.attribute_value_id, 0) AS attribute_value_id, ISNULL(A.attribute_id, 0) AS attribute_id, ISNULL(A.name, '') AS name, ISNULL(A.is_hidden_sku, 0) AS is_hidden_sku,ISNULL(A.is_hidden_title, 0) AS is_hidden_title from pc_attribute_values A where attribute_id=" & item.UniqueID)

            'If (collection.Count <> 0) Then


            '    'sb.Append("<ul>")

            '    For Each item As RadComboBoxItem In collection
            '        dt_atribvalues = SqlHelper.ExecuteDatatable("update pc_attribute_values set is_hidden_sku = " + item.UniqueID + " where attribute_value_id =" & ComboBox.DataValueField("attribute_value_id"))


            '    Next

            '    'sb.Append("</ul>")


            'Else

            'End If


        End Sub



        Protected Sub btn__sku_layout_Click(sender As Object, e As System.EventArgs) Handles btn__sku_layout.Click

            ShowCheckedItems()

        End Sub

 


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>