ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Enable Disable Bootstrap SelectPicker DropDownList using jQuery in ASP.Net<p>Hi&nbsp;Warren,</p> <p>Refer the modified code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;asp:Label ID=&#34;LabelFullname&#34; Text=&#34;Test&#34; runat=&#34;server&#34; /&gt; &lt;asp:GridView ID=&#34;gvtfaTrust&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;False&#34; OnRowDataBound=&#34;gvtfaTrust_RowDataBound&#34; DataKeyNames=&#34;ID&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;ID&#34; HeaderText=&#34;0. ID&#34; ShowHeader=&#34;false&#34; HeaderStyle-Wrap=&#34;false&#34; SortExpression=&#34;ID&#34; /&gt; &lt;asp:BoundField DataField=&#34;BankAccount&#34; HeaderText=&#34;1. Bank Account&#34; HeaderStyle-Wrap=&#34;false&#34; SortExpression=&#34;BankAccount&#34; Visible=&#34;false&#34; /&gt; &lt;asp:BoundField DataField=&#34;DateDeposited&#34; HeaderText=&#34;2. Date Deposited&#34; DataFormatString=&#34;{0:dd, MMM yyyy}&#34; HeaderStyle-Wrap=&#34;false&#34; SortExpression=&#34;DateDeposited&#34; /&gt; &lt;asp:BoundField DataField=&#34;PayName&#34; HeaderText=&#34;3. Payee&#34; HeaderStyle-Wrap=&#34;false&#34; SortExpression=&#34;PayName&#34; /&gt; &lt;asp:BoundField DataField=&#34;Reference&#34; HeaderText=&#34;4. Reference&#34; HeaderStyle-Wrap=&#34;false&#34; SortExpression=&#34;Reference&#34; /&gt; &lt;asp:BoundField DataField=&#34;Memo&#34; HeaderText=&#34;5. Memo&#34; HeaderStyle-Wrap=&#34;false&#34; SortExpression=&#34;Memo&#34; /&gt; &lt;asp:BoundField DataField=&#34;EntryType&#34; HeaderText=&#34;6. Entry Type&#34; HeaderStyle-Wrap=&#34;false&#34; SortExpression=&#34;EntryType&#34; /&gt; &lt;asp:TemplateField HeaderText=&#34;7. GL Account&#34; HeaderStyle-HorizontalAlign=&#34;Left&#34; SortExpression=&#34;GLAcct&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID=&#34;LabelGLAcct&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;GLAcct&#34;) %&gt;&#39; Visible=&#34;false&#34;&gt;&lt;/asp:Label&gt; &lt;asp:DropDownList ID=&#34;DropdownlistGLAcct&#34; runat=&#34;server&#34; Visible=&#34;false&#34; CssClass=&#34;selectpicker show-tick form-control Update&#34; data-style=&#34;btn btn-default btn-sm&#34; data-live-search-style=&#34;true&#34; data-live-search=&#34;true&#34;&gt; &lt;asp:ListItem Text=&#34;text 1&#34; /&gt; &lt;asp:ListItem Text=&#34;text 2&#34; /&gt; &lt;/asp:DropDownList&gt; &lt;/ItemTemplate&gt; &lt;HeaderStyle HorizontalAlign=&#34;Left&#34; Wrap=&#34;false&#34; /&gt; &lt;/asp:TemplateField&gt; &lt;asp:BoundField DataField=&#34;Amount&#34; HeaderText=&#34;8. Amount&#34; DataFormatString=&#34;{0:C}&#34; HeaderStyle-Wrap=&#34;false&#34; SortExpression=&#34;Amount&#34; /&gt; &lt;asp:TemplateField HeaderText=&#34;9. Exchange&#34; SortExpression=&#34;ExchangeRate&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID=&#34;LabelExchangeRate&#34; runat=&#34;server&#34; Text=&#39;&lt;%# String.Format(&#34;{0:0.00000}&#34;, Eval(&#34;ExchangeRate&#34;)) %&gt;&#39; Visible=&#34;false&#34;&gt;&lt;/asp:Label&gt; &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;TextExchangeRate&#34; Text=&#39;&lt;%# Eval(&#34;ExchangeRate&#34;, &#34;{0:0.00000}&#34;) %&gt;&#39; CssClass=&#34;btn-sm form-control Update&#34; Width=&#34;65px&#34; Enabled=&#39;&lt;%# Eval(&#34;IsExchangeRate&#34;) %&gt;&#39; data-mask=&#34;#.##000&#34; /&gt; &lt;/ItemTemplate&gt; &lt;HeaderStyle Wrap=&#34;False&#34; /&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText=&#34;10. Details&#34; HeaderStyle-Wrap=&#34;false&#34; SortExpression=&#34;details&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:LinkButton ID=&#34;btnSelect&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;Details&#34;) %&gt;&#39; CommandName=&#34;Select&#34; CommandArgument=&#34;&lt;%# Container.DataItemIndex %&gt;&#34; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText=&#34;11. Mark&#34; HeaderStyle-Wrap=&#34;false&#34; SortExpression=&#34;Marked&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID=&#34;btnMark&#34; runat=&#34;server&#34; Checked=&#39;&lt;%# Eval(&#34;Marked&#34;) %&gt;&#39; CssClass=&#34;form-check-input Mark&#34; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText=&#34;12. Ignore&#34; HeaderStyle-Wrap=&#34;false&#34; SortExpression=&#34;Ignore&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID=&#34;btnIgnore&#34; runat=&#34;server&#34; AutoPostBack=&#34;true&#34; Checked=&#39;&lt;%# Eval(&#34;Ignore&#34;) %&gt;&#39; OnCheckedChanged=&#34;Ignore_Click&#34; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;SelectedRowStyle BackColor=&#34;lightyellow&#34; /&gt; &lt;PagerSettings Mode=&#34;NumericFirstLast&#34; /&gt; &lt;PagerStyle CssClass=&#34;pagination-ys&#34; HorizontalAlign=&#34;Left&#34; /&gt; &lt;/asp:GridView&gt; &lt;link rel=&#34;stylesheet&#34; href=&#34;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css&#34; /&gt; &lt;link rel=&#34;stylesheet&#34; href=&#34;https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.2/css/bootstrap-select.min.css&#34; /&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.2/js/bootstrap-select.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(function () { $(&#39;.Mark&#39;).on(&#39;change&#39;, function () { var id = $(this).closest(&#39;tr&#39;).find(&#39;td&#39;).eq(0).html(); var checkbox = $(this).closest(&#39;tr&#39;).find(&#39;[id*=btnMark]&#39;); var Marked = $(this).closest(&#39;tr&#39;).find(&#39;[id*=btnMark]:checked&#39;).val(); var DropdownlistGLAcct = $(this).closest(&#39;tr&#39;).find(&#39;[id*=DropdownlistGLAcct]&#39;); var LabelGLAcct = $(this).closest(&#39;tr&#39;).find(&#39;[id*=LabelGLAcct]&#39;); var TextExchangeRate = $(this).closest(&#39;tr&#39;).find(&#39;[id*=TextExchangeRate]&#39;); var LabelFullname = document.getElementById(&#39;&lt;%=LabelFullname.ClientID%&gt;&#39;).innerText; $.ajax({ type: &#34;POST&#34;, url: &#34;Default.aspx/Mark&#34;, data: &#34;{id:&#34; + id + &#34;,Marked:&#39;&#34; + Marked + &#34;&#39;, LabelFullname:&#39;&#34; + LabelFullname + &#34;&#39;}&#34;, contentType: &#34;application/json; charset=utf-8&#34;, dataType: &#34;json&#34;, error: function (jqXHR, textStatus, errorThrown) { alert(&#34;get session failed &#34; + errorThrown); }, success: function (response) { if (response.d == &#34;failed&#34;) { $(checkbox).prop(&#39;checked&#39;, false); $(DropdownlistGLAcct).prop(&#34;disabled&#34;, false); $(DropdownlistGLAcct).closest(&#39;td&#39;).find(&#39;button&#39;).removeClass(&#39;disabled&#39;); } else { if ($(checkbox).prop(&#39;checked&#39;) == false) { $(TextExchangeRate).prop(&#34;disabled&#34;, false); $(DropdownlistGLAcct).prop(&#34;disabled&#34;, false); $(DropdownlistGLAcct).closest(&#39;td&#39;).find(&#39;button&#39;).removeClass(&#39;disabled&#39;); } else { $(TextExchangeRate).prop(&#34;disabled&#34;, true); $(DropdownlistGLAcct).prop(&#34;disabled&#34;, true); $(DropdownlistGLAcct).closest(&#39;td&#39;).find(&#39;button&#39;).addClass(&#34;disabled&#34;); } } } }); }); }); &lt;/script&gt;</pre> <p><strong><span style="text-decoration: underline;">Namespaces</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data; using System.Web.Services;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data Imports System.Web.Services</pre> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;ID&#34;, typeof(int)), new DataColumn(&#34;BankAccount&#34;, typeof(string)), new DataColumn(&#34;DateDeposited&#34;, typeof(string)), new DataColumn(&#34;PayName&#34;, typeof(string)), new DataColumn(&#34;Reference&#34;, typeof(string)), new DataColumn(&#34;Memo&#34;, typeof(string)), new DataColumn(&#34;EntryType&#34;, typeof(int)), new DataColumn(&#34;GLAcct&#34;, typeof(string)), new DataColumn(&#34;Amount&#34;, typeof(int)), new DataColumn(&#34;ExchangeRate&#34;, typeof(int)), new DataColumn(&#34;IsExchangeRate&#34;, typeof(bool)), new DataColumn(&#34;Details&#34;, typeof(string)), new DataColumn(&#34;Marked&#34;, typeof(bool)), new DataColumn(&#34;Ignore&#34;, typeof(bool)) }); dt.Rows.Add(1, &#34;111&#34;, &#34;01/02/2018&#34;, &#34;BN&#34;, &#34;123455AAA&#34;, &#34;CM&#34;, 124, &#34;GA&#34;, 100, 5, true, &#34;Details&#34;, true, true); dt.Rows.Add(2, &#34;222&#34;, &#34;02/02/2018&#34;, &#34;BN1&#34;, &#34;123455AAA112&#34;, &#34;CM1&#34;, 12411, &#34;GA1&#34;, 200, 6, true, &#34;Details&#34;, true, false); gvtfaTrust.DataSource = dt; gvtfaTrust.DataBind(); } } protected void Ignore_Click(object sender, EventArgs e) { } [WebMethod()] public static string Mark(int id, string Marked, string LabelFullname) { try { int age = int.Parse(&#34;1&#34;); return &#34;success&#34;; } catch (Exception ex) { return &#34;failed&#34;; } } protected void gvtfaTrust_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.Cells[11].Controls.OfType&lt;CheckBox&gt;().FirstOrDefault().Checked) { e.Row.Cells[7].Controls.OfType&lt;DropDownList&gt;().FirstOrDefault().Enabled = false; e.Row.Cells[7].Controls.OfType&lt;DropDownList&gt;().FirstOrDefault().Visible = true; e.Row.Cells[7].Controls.OfType&lt;Label&gt;().FirstOrDefault().Visible = true; e.Row.Cells[9].Controls.OfType&lt;TextBox&gt;().FirstOrDefault().Enabled = false; e.Row.Cells[12].Controls.OfType&lt;CheckBox&gt;().FirstOrDefault().Enabled = false; } } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not Me.IsPostBack Then Dim dt As DataTable = New DataTable() dt.Columns.AddRange(New DataColumn() { New DataColumn(&#34;ID&#34;, GetType(Integer)), New DataColumn(&#34;BankAccount&#34;, GetType(String)), New DataColumn(&#34;DateDeposited&#34;, GetType(String)), New DataColumn(&#34;PayName&#34;, GetType(String)), New DataColumn(&#34;Reference&#34;, GetType(String)), New DataColumn(&#34;Memo&#34;, GetType(String)), New DataColumn(&#34;EntryType&#34;, GetType(Integer)), New DataColumn(&#34;GLAcct&#34;, GetType(String)), New DataColumn(&#34;Amount&#34;, GetType(Integer)), New DataColumn(&#34;ExchangeRate&#34;, GetType(Integer)), New DataColumn(&#34;IsExchangeRate&#34;, GetType(Boolean)), New DataColumn(&#34;Details&#34;, GetType(String)), New DataColumn(&#34;Marked&#34;, GetType(Boolean)), New DataColumn(&#34;Ignore&#34;, GetType(Boolean))}) dt.Rows.Add(1, &#34;111&#34;, &#34;01/02/2018&#34;, &#34;BN&#34;, &#34;123455AAA&#34;, &#34;CM&#34;, 124, &#34;GA&#34;, 100, 5, True, &#34;Details&#34;, True, True) dt.Rows.Add(2, &#34;222&#34;, &#34;02/02/2018&#34;, &#34;BN1&#34;, &#34;123455AAA112&#34;, &#34;CM1&#34;, 12411, &#34;GA1&#34;, 200, 6, True, &#34;Details&#34;, True, False) gvtfaTrust.DataSource = dt gvtfaTrust.DataBind() End If End Sub Protected Sub Ignore_Click(ByVal sender As Object, ByVal e As EventArgs) End Sub &lt;WebMethod()&gt; Public Shared Function Mark(ByVal id As Integer, ByVal Marked As String, ByVal LabelFullname As String) As String Try Dim age As Integer = Integer.Parse(&#34;1&#34;) Return &#34;success&#34; Catch ex As Exception Return &#34;failed&#34; End Try End Function Protected Sub gvtfaTrust_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvtfaTrust.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.Cells(11).Controls.OfType(Of CheckBox)().FirstOrDefault().Checked Then e.Row.Cells(7).Controls.OfType(Of DropDownList)().FirstOrDefault().Enabled = False e.Row.Cells(7).Controls.OfType(Of DropDownList)().FirstOrDefault().Visible = True e.Row.Cells(7).Controls.OfType(Of Label)().FirstOrDefault().Visible = True e.Row.Cells(9).Controls.OfType(Of TextBox)().FirstOrDefault().Enabled = False e.Row.Cells(12).Controls.OfType(Of CheckBox)().FirstOrDefault().Enabled = False End If End If End Sub</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="https://i.imgur.com/JhpIW4A.gif" alt="" width="472" height="133" /></span></strong></p>https://www.aspforums.net:443/Threads/133993/Enable-Disable-Bootstrap-SelectPicker-DropDownList-using-jQuery-in-ASPNet/https://www.aspforums.net:443/Threads/133993/Enable-Disable-Bootstrap-SelectPicker-DropDownList-using-jQuery-in-ASPNet/Thu, 27 Dec 2018 01:05:41 GMT