1
Thanks for paste your code. You can do one thing. Create a method for only bind select query option. And call it on page load and then your problem will solve.
1
hey amit below is my binding code
gridview code :
- <asp:GridView ID="GridView1" runat="server" BackColor="White"
- BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3"
- ForeColor="Black" GridLines="Vertical" Height="172px" Width="879px"
- AllowPaging="True" onpageindexchanging="OnPageIndexChanging">
- <AlternatingRowStyle BackColor="#CCCCCC" />
- <Columns>
- <asp:TemplateField HeaderText="Sr. No">
- <ItemTemplate>
- <%#Container.DataItemIndex+1 %>
- </ItemTemplate>
- </asp:TemplateField>
- </Columns>
- <FooterStyle BackColor="#CCCCCC" />
- <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
- <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
- <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
- <SortedAscendingCellStyle BackColor="#F1F1F1" />
- <SortedAscendingHeaderStyle BackColor="#808080" />
- <SortedDescendingCellStyle BackColor="#CAC9C9" />
- <SortedDescendingHeaderStyle BackColor="#383838" />
- </asp:GridView>
binding code
- protected void DropDownGrid()
- {
- string orgname = OrgNM;
- SqlConnection con = new SqlConnection(kkd);
-
- if (DropDownList1.SelectedItem.Text == "select")
- {
-
- con.Open();
-
- SqlCommand cmd = new SqlCommand("select query' ", con);
-
- cmd.Parameters.AddWithValue("@orgname", orgname);
- SqlDataAdapter da = new SqlDataAdapter(cmd);
-
- DataSet ds = new DataSet();
- da.Fill(ds);
- GridView1.DataSource = ds;
- GridView1.DataBind();
- con.Close();
-
-
-
-
-
- }
- else if (DropDownList1.SelectedItem.Text == "Active Projects")
- {
- con.Open();
-
- SqlCommand cmd = new SqlCommand("select query, con);
-
- cmd.Parameters.AddWithValue("@orgname", orgname);
- SqlDataAdapter da = new SqlDataAdapter(cmd);
-
- DataSet ds = new DataSet();
- da.Fill(ds);
- GridView1.DataSource = ds;
- GridView1.DataBind();
- con.Close();
-
- }
- else if (DropDownList1.SelectedItem.Text == "Past Projects")
- {
- con.Open();
-
- SqlCommand cmd = new SqlCommand("select query", con);
-
- cmd.Parameters.AddWithValue("@orgname", orgname);
- SqlDataAdapter da = new SqlDataAdapter(cmd);
-
- DataSet ds = new DataSet();
- da.Fill(ds);
- GridView1.DataSource = ds;
- GridView1.DataBind();
- con.Close();
-
- }
-
- }
i have 3 options in gridview
1st=> select
2nd=> active projects
3rd=> past projects
when page load i wanted to fire selet option query

1
hey rupesh mine is not an mvc architicture
1
Hi,
Can you show me your binding code ?
1
After your page load write one ajax call which will take value from current drop down & passes to action method, now from action method returns data into Json, JsonResult, List format & bind to your grid / div.
Refer my article which has a button click event & on button click event I had ajax call & taking data from action result & binding it. Just for your reference
1) https://www.c-sharpcorner.com/article/different-json-result-types-used-in-mvc/
2) https://www.c-sharpcorner.com/article/dynamically-bind-the-dropdownlist-on-change-event-in-asp-net-mvc-5/
Let me know if any concern.