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.Show Hide ASP.Net GridView AutoGenerate Select Button based on DropDownList using C# and VB.Net<p>Hi <a class="username" rel="akhter"> akhter</a>,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;asp:DropDownList ID=&#34;ddlStatus&#34; runat=&#34;server&#34; AutoPostBack=&#34;true&#34; OnSelectedIndexChanged=&#34;Changed&#34;&gt; &lt;asp:ListItem Selected=&#34;True&#34;&gt;Select&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;Receive&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;Pending&lt;/asp:ListItem&gt; &lt;/asp:DropDownList&gt; &lt;hr /&gt; &lt;asp:GridView runat=&#34;server&#34; ID=&#34;GridView1&#34; AutoGenerateColumns=&#34;False&#34; AutoGenerateSelectButton=&#34;true&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;ID&#34; HeaderText=&#34;ID&#34; /&gt; &lt;asp:BoundField DataField=&#34;Name&#34; HeaderText=&#34;Name&#34; /&gt; &lt;asp:BoundField DataField=&#34;Country&#34; HeaderText=&#34;Country&#34; /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt;</pre> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">private void BindgridView() { &nbsp;&nbsp;&nbsp; System.Data.DataTable dt = new System.Data.DataTable(); &nbsp;&nbsp;&nbsp; dt.Columns.AddRange(new System.Data.DataColumn[] { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new System.Data.DataColumn("Id", typeof(int)), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new System.Data.DataColumn("Name", typeof(string)), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new System.Data.DataColumn("Country",typeof(string)) }); &nbsp;&nbsp;&nbsp; dt.Rows.Add(1, "John Hammond", "United States"); &nbsp;&nbsp;&nbsp; dt.Rows.Add(2, "Mudassar Khan", "India"); &nbsp;&nbsp;&nbsp; dt.Rows.Add(3, "Suzanne Mathews", "France"); &nbsp;&nbsp;&nbsp; dt.Rows.Add(4, "Robert Schidner", "Russia"); &nbsp;&nbsp;&nbsp; GridView1.DataSource = dt; &nbsp;&nbsp;&nbsp; GridView1.DataBind(); } protected void Changed(object sender, EventArgs e) { &nbsp;&nbsp;&nbsp; statsGRN(); } private void statsGRN() { &nbsp;&nbsp;&nbsp; if (ddlStatus.SelectedItem.Text.Trim().ToLower() == "pending") &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.GridView1.AutoGenerateSelectButton = true; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.BindgridView(); &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; else if (ddlStatus.SelectedItem.Text.Trim().ToLower() == "receive") &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.GridView1.AutoGenerateSelectButton = false; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.BindgridView(); &nbsp;&nbsp;&nbsp; } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Private Sub BindgridView() Dim dt As System.Data.DataTable = New System.Data.DataTable() dt.Columns.AddRange(New System.Data.DataColumn() { New System.Data.DataColumn(&#34;Id&#34;, GetType(Integer)), New System.Data.DataColumn(&#34;Name&#34;, GetType(String)), New System.Data.DataColumn(&#34;Country&#34;, GetType(String))}) dt.Rows.Add(1, &#34;John Hammond&#34;, &#34;United States&#34;) dt.Rows.Add(2, &#34;Mudassar Khan&#34;, &#34;India&#34;) dt.Rows.Add(3, &#34;Suzanne Mathews&#34;, &#34;France&#34;) dt.Rows.Add(4, &#34;Robert Schidner&#34;, &#34;Russia&#34;) GridView1.DataSource = dt GridView1.DataBind() End Sub Protected Sub Changed(ByVal sender As Object, ByVal e As EventArgs) statsGRN() End Sub Private Sub statsGRN() If ddlStatus.SelectedItem.Text.Trim().ToLower() = &#34;pending&#34; Then Me.GridView1.AutoGenerateSelectButton = True Me.BindgridView() ElseIf ddlStatus.SelectedItem.Text.Trim().ToLower() = &#34;receive&#34; Then Me.GridView1.AutoGenerateSelectButton = False Me.BindgridView() End If End Sub</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><img src="https://i.imgur.com/0PShtYb.gif" alt="" width="293" height="183" /></p>https://www.aspforums.net:443/Threads/423008/Show-Hide-ASPNet-GridView-AutoGenerate-Select-Button-based-on-DropDownList-using-C-and-VBNet/https://www.aspforums.net:443/Threads/423008/Show-Hide-ASPNet-GridView-AutoGenerate-Select-Button-based-on-DropDownList-using-C-and-VBNet/Thu, 17 Oct 2019 07:20:47 GMT