in Education by
I have been developing a webpage which uses n number of dropdownlists which are binding dynamically inside a gridview. I want to perform operations based on the dropdownlist's selectedindexchanged event. I had done that and working good, but when I changed dropdownlist on second time It does postback but not calls the event. You can see my code here <%@ Page Language="C#" AutoEventWireup="true" CodeFile="gridDropDownTest.aspx.cs" Inherits="gridDropDownTest" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
using System; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; public partial class gridDropDownTest : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { databind(); } public void databind() { DataTable dt = new DataTable(); dt.Columns.Add("Mode"); dt.Rows.Add(""); dt.Rows.Add(""); gridLedgeDetails.DataSource = dt; gridLedgeDetails.DataBind(); } protected void OnRowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { DropDownList ddlMode = new DropDownList(); ddlMode.Width = 90; ddlMode.Attributes.Add("style", "background-color:#ff6600;"); ddlMode.Items.Add("Regular"); ddlMode.Items.Add("Monthwise"); ddlMode.SelectedIndexChanged += new EventHandler(ddlMode_Indexchanged); ddlMode.AutoPostBack = true; ddlMode.ID = "ddlMode_"; e.Row.Cells[0].Controls.Add(ddlMode); } } protected void gridLedgeDetails_DataBound(object sender, EventArgs e) { } protected void ddlMode_Indexchanged(object sender, EventArgs e) { string uid = this.Page.Request.Params.Get("__EVENTTARGET"); if (uid != null && uid.Contains("ddlMode_")) { string[] values = uid.Split('$'); string row = values[1].Replace("ctl", ""); Control ctrl = Page.FindControl(uid); DropDownList ddl = (DropDownList)ctrl; if (ddl.SelectedIndex == 1) { } } } } enter image description here JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
For this you need to take and bind the dropdownlist again in Page_PreInit page method. For Example.... protected void Page_PreInit(object sender, EventArgs e) { // here you need to build the gridview again. // then the state will retain same...... }

Related questions

0 votes
    So the problem is i don't get get a value from textbox field on GridView RowUpdating event. Here ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 8, 2022 in Education by JackTerrance
0 votes
    I have a Login control placed inside LoginView control contained within a PANEL. I want to set login button ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 8, 2022 in Education by JackTerrance
0 votes
    All How can I download a file so the user sees that it is downloading (like with a stream?) I ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I'm working on a DNN skin using Christoc's DNN templates and when I create a normal ASP.NET ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    I have tried many solution online but I am unable to fix. First off all i check in bin and it ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I have a database (SQL Server) with clients and a MVC plataform, and i want a row to be "hidden ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I have a database (SQL Server) with clients and a MVC plataform, and i want a row to be "hidden ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    i create this class and it have this constructor : public class ReturnResult : ImplicitReturnResult { public bool ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    Pulling my hair out here. All was working fine, and then out of the blue, I started to get some ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    newbie question: how do i make my JSON output ignore null values? I don't want to necessarily set ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    newbie question: how do i make my JSON output ignore null values? I don't want to necessarily set ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    For example, I have an ASP.NET form that is called by another aspx: string url = "http:// ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    Need to read my SMTP email settings defined under system.net section in my web.config file. Below is one example of SMTP email setting defined in web.config file: (Under Section)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I have an SQL table in the following format: id categoryname parent id 1 cat1 0 2 cat2 1 3 cat3 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
0 votes
    I have an SQL table in the following format: id categoryname parent id 1 cat1 0 2 cat2 1 3 cat3 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
...