Hi akhter,
Check this example. Now please take its reference and correct your code.
HTML
<asp:DropDownList ID="ddlStatus" runat="server" AutoPostBack="true" OnSelectedIndexChanged="Changed">
<asp:ListItem Selected="True">Select</asp:ListItem>
<asp:ListItem>Receive</asp:ListItem>
<asp:ListItem>Pending</asp:ListItem>
</asp:DropDownList>
<hr />
<asp:GridView runat="server" ID="GridView1" AutoGenerateColumns="False" AutoGenerateSelectButton="true">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Country" HeaderText="Country" />
</Columns>
</asp:GridView>
Code
C#
private void BindgridView()
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.AddRange(new System.Data.DataColumn[] {
new System.Data.DataColumn("Id", typeof(int)),
new System.Data.DataColumn("Name", typeof(string)),
new System.Data.DataColumn("Country",typeof(string)) });
dt.Rows.Add(1, "John Hammond", "United States");
dt.Rows.Add(2, "Mudassar Khan", "India");
dt.Rows.Add(3, "Suzanne Mathews", "France");
dt.Rows.Add(4, "Robert Schidner", "Russia");
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void Changed(object sender, EventArgs e)
{
statsGRN();
}
private void statsGRN()
{
if (ddlStatus.SelectedItem.Text.Trim().ToLower() == "pending")
{
this.GridView1.AutoGenerateSelectButton = true;
this.BindgridView();
}
else if (ddlStatus.SelectedItem.Text.Trim().ToLower() == "receive")
{
this.GridView1.AutoGenerateSelectButton = false;
this.BindgridView();
}
}
VB.Net
Private Sub BindgridView()
Dim dt As System.Data.DataTable = New System.Data.DataTable()
dt.Columns.AddRange(New System.Data.DataColumn() {
New System.Data.DataColumn("Id", GetType(Integer)),
New System.Data.DataColumn("Name", GetType(String)),
New System.Data.DataColumn("Country", GetType(String))})
dt.Rows.Add(1, "John Hammond", "United States")
dt.Rows.Add(2, "Mudassar Khan", "India")
dt.Rows.Add(3, "Suzanne Mathews", "France")
dt.Rows.Add(4, "Robert Schidner", "Russia")
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() = "pending" Then
Me.GridView1.AutoGenerateSelectButton = True
Me.BindgridView()
ElseIf ddlStatus.SelectedItem.Text.Trim().ToLower() = "receive" Then
Me.GridView1.AutoGenerateSelectButton = False
Me.BindgridView()
End If
End Sub
Screenshot