Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8459597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:22:30+00:00 2026-06-10T13:22:30+00:00

I am binding dropdown list and checkbox list in a gridview using templatefield.But neither

  • 0

I am binding dropdown list and checkbox list in a gridview using templatefield.But neither OnSelectedIndexChanged event of gridview nor OnCheckedChanged event of check box is getting fire.

This is aspx file code.

    <form id="form1" runat="server">
    <div>

    </div>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="username"  OnRowEditing="row_edit" OnRowDeleting="row_delete">
    <Columns>
    <asp:TemplateField HeaderText="Fetch_username">
    <ItemTemplate>
    <asp:Label ID="labelusername" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "username")%>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>

      <asp:TemplateField HeaderText="Fetch_firstname">
    <ItemTemplate>
    <asp:Label ID="labelfirstname" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "firstname")%>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>

      <asp:TemplateField HeaderText="Fetch_lastname">
    <ItemTemplate>
    <asp:Label ID="labellastname" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "lastname")%>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>

      <asp:TemplateField HeaderText="Fetch_address">
    <ItemTemplate>
    <asp:Label ID="labeladdress" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "address")%>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>


                <asp:TemplateField HeaderText="">
                  <ItemTemplate>
                      <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Delete">Delete</asp:LinkButton>
                  </ItemTemplate>
              </asp:TemplateField>

                  <asp:TemplateField HeaderText="">
                  <ItemTemplate>
                      <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit">Edit</asp:LinkButton>
                  </ItemTemplate>
              </asp:TemplateField>

               <asp:TemplateField HeaderText="">
                  <ItemTemplate>
                      <asp:LinkButton ID="LinkButton3" runat="server" CommandName="View">View</asp:LinkButton>
                  </ItemTemplate>
              </asp:TemplateField>

               <asp:TemplateField HeaderText="Change Color">
                    <ItemTemplate>
                        <asp:DropDownList ID="dropdownid" DataSourceID="sqldatasource_id" DataTextField="username"
                            BackColor="Yellow"  OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AppendDataBoundItems="True" runat="server" AutoPostBack="True">

                            <asp:ListItem Text="" Value="" Selected="True" />
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>

                    <asp:TemplateField HeaderText="Change Color">
                    <ItemTemplate>
                      <asp:CheckBox ID="checkbox" runat="server" AutoPostBack="true" OnCheckedChanged="checked_delete" />
                    </ItemTemplate>
                </asp:TemplateField>

    </Columns>
    </asp:GridView>
    <asp:Button ID="delete_checkedbox" runat="server" Text="Delete Using Checkbox" OnClick="delete_box" />
    <asp:DropDownList ID="ddlist" runat="server"  OnSelectedIndexChanged="index_changed" AutoPostBack="True"  BackColor="Blue" >
        <asp:ListItem Text="1" Value="" Selected="True" />
            <asp:ListItem Text="2" Value="" Selected="False" />
                <asp:ListItem Text="3" Value="" Selected="False" />
                    <asp:ListItem Text="4" Value="" Selected="False" />
                        <asp:ListItem Text="5" Value="" Selected="False" />
    </asp:DropDownList>

       <div id="hee" runat="server">
    <div class="postionform">
    <table border=1>
    <tr>
    <td><asp:Label ID="label" Text="Username:" runat="server" /></td>
    <td><asp:TextBox ID="textbox"  BackColor="Silver" runat="server" /></td> <br />
    </tr>
    <tr>
     <td><asp:Label ID="label1" Text="Last-name:" runat="server" /></td>
    <td><asp:TextBox ID="textbox1"  BackColor="Silver" runat="server" /> </td><br />
    </tr>
    <tr>  
     <td><asp:Label ID="label2" Text="Last-name:" runat="server" /></td>
   <td>  <asp:TextBox ID="textbox2"  BackColor="Silver" runat="server" /> </td><br />
   </tr>
   <tr>
     <td><asp:Label ID="label3" Text="Address:" runat="server" /></td>
     <td><asp:TextBox ID="textbox3"  BackColor="Silver" runat="server" /></td> <br />
     </tr>
    <tr>
    <td><asp:Button ID="button_update" runat="server" OnClick="update_click" Text="Update" /></td>
    <td><asp:Button ID="button_cancel" runat="server" OnClick="cancel_click" Text="Cancel" /></td>
    </tr>
  </table>
  </div>
    </div>
     <asp:SqlDataSource ID="sqldatasource_id" runat="server" ConnectionString="<%$ ConnectionStrings:crudconnection %>"
            SelectCommand="SELECT [username] FROM [crudtable]"></asp:SqlDataSource>
    <br />
    <br />
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
        DataSourceID="sqldatasource_id" DataTextField="username" 
        DataValueField="username" OnSelectedIndexChanged="change">
    </asp:DropDownList>
    <asp:Label ID="label_for" Text="" runat="server" />
    <asp:Label ID="checked_label" Text="" runat="server" />
    </form>

This is Cs file code.

  protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
    DropDownList ddl = (DropDownList)sender;
     GridViewRow row = (GridViewRow)ddl.NamingContainer;
  int count = 0;
  int g = row.RowIndex + 3;
  int current_row_index = row.RowIndex;
  foreach (GridViewRow gvRow in GridView1.Rows)
  {

      gvRow.BackColor = Color.White;
      if (((DropDownList)gvRow.FindControl("dropdownid")).SelectedIndex != 0)
      {
          count++;
      }

      if (gvRow.FindControl("dropdownid") != null && gvRow.RowIndex != current_row_index)
      {
          ((DropDownList)gvRow.FindControl("dropdownid")).SelectedIndex = 0;
      }
    }
     GridView1.Rows[g].BackColor = Color.Red;
     if (count == 0)
     {
      foreach (GridViewRow gvRow in GridView1.Rows)
      {
          gvRow.BackColor = Color.White;
      }
    }
    }
    protected void checked_delete(object sender, EventArgs e)
    {
    CheckBox chk = (CheckBox)sender;
    GridViewRow gr = (GridViewRow)chk.Parent.Parent;
    checked_label.Text = GridView1.DataKeys[gr.RowIndex].Value.ToString();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:22:31+00:00Added an answer on June 10, 2026 at 1:22 pm

    i solved it.Actually i am binding data in gridview in page_load.So i forgot to put the code(which binds the data to grid view and placed inside page_load) inside

    (!IsPostBack){}.
    

    Hope it will help someone.
    Thanks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am binding dropdown list using Object data source. I got an error like
in the aspx page i am getting this error while binding dropdown list Unable
When binding code to the execution of an event using mxml, by assigning the
I have a dropdown list that I am binding to a datatable. Here is
I am using MVC3. I'm binding the dropdown with the Data coming from a
I'm using the options binding on a select list used in a jQuery template:
I have two cascading dropdowns and one gridview control. on page load iam binding
After binding the scroll event to an object, how can I get the amount
When Binding a GridView to a DataTable, How can we Change the value displayed
The Binding syntax, {Binding /} , works in WPF but does not work at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.