6
Answers

Looking for SEO Expert...

Help me to find someone...!!!
Answers (6)
1
Amit Kumar

Amit Kumar

284 6.6k 3.9m 6y
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
Subin Thomas

Subin Thomas

NA 4.9k 133.6k 6y
hey amit below is my binding code
 
gridview code :
  1.  <asp:GridView ID="GridView1" runat="server" BackColor="White"   
  2.         BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3"   
  3.         ForeColor="Black" GridLines="Vertical" Height="172px" Width="879px"   
  4.             AllowPaging="True" onpageindexchanging="OnPageIndexChanging">  
  5.         <AlternatingRowStyle BackColor="#CCCCCC" />  
  6.         <Columns>  
  7.             <asp:TemplateField HeaderText="Sr. No">  
  8.             <ItemTemplate>  
  9.                 <%#Container.DataItemIndex+1 %>  
  10.             </ItemTemplate>  
  11.             </asp:TemplateField>  
  12.         </Columns>  
  13.         <FooterStyle BackColor="#CCCCCC" />  
  14.         <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />  
  15.         <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />  
  16.         <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />  
  17.         <SortedAscendingCellStyle BackColor="#F1F1F1" />  
  18.         <SortedAscendingHeaderStyle BackColor="#808080" />  
  19.         <SortedDescendingCellStyle BackColor="#CAC9C9" />  
  20.         <SortedDescendingHeaderStyle BackColor="#383838" />  
  21. </asp:GridView> 
  binding code
  1. protected void DropDownGrid()  
  2.         {  
  3.             string orgname = OrgNM;  
  4.             SqlConnection con = new SqlConnection(kkd);  
  5.   
  6.             if (DropDownList1.SelectedItem.Text == "select")  
  7.             {  
  8.   
  9.                 con.Open();  
  10.   
  11.                 SqlCommand cmd = new SqlCommand("select query' ", con);  
  12.   
  13.                 cmd.Parameters.AddWithValue("@orgname", orgname);  
  14.                 SqlDataAdapter da = new SqlDataAdapter(cmd);  
  15.   
  16.                 DataSet ds = new DataSet();  
  17.                 da.Fill(ds);  
  18.                 GridView1.DataSource = ds;  
  19.                 GridView1.DataBind();  
  20.                 con.Close();  
  21.   
  22.   
  23.   
  24.   
  25.   
  26.             }  
  27.             else if (DropDownList1.SelectedItem.Text == "Active Projects")  
  28.             {  
  29.                 con.Open();  
  30.   
  31.                 SqlCommand cmd = new SqlCommand("select query, con);  
  32.   
  33.                 cmd.Parameters.AddWithValue("@orgname", orgname);  
  34.                 SqlDataAdapter da = new SqlDataAdapter(cmd);  
  35.   
  36.                 DataSet ds = new DataSet();  
  37.                 da.Fill(ds);  
  38.                 GridView1.DataSource = ds;  
  39.                 GridView1.DataBind();  
  40.                 con.Close();  
  41.   
  42.             }  
  43.             else if (DropDownList1.SelectedItem.Text == "Past Projects")  
  44.             {  
  45.                 con.Open();  
  46.   
  47.                 SqlCommand cmd = new SqlCommand("select query", con);  
  48.   
  49.                 cmd.Parameters.AddWithValue("@orgname", orgname);  
  50.                 SqlDataAdapter da = new SqlDataAdapter(cmd);  
  51.   
  52.                 DataSet ds = new DataSet();  
  53.                 da.Fill(ds);  
  54.                 GridView1.DataSource = ds;  
  55.                 GridView1.DataBind();  
  56.                 con.Close();  
  57.   
  58.             }  
  59.   
  60.         } 
 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
Subin Thomas

Subin Thomas

NA 4.9k 133.6k 6y
hey rupesh mine is not an mvc architicture
1
Amit Kumar

Amit Kumar

284 6.6k 3.9m 6y
Hi,
    Can you show me your binding code ?
 
1
Rupesh Kahane

Rupesh Kahane

101 19.1k 4.2m 6y

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.