I'm creating a custom control where I'm extending the GridView class for custom paging. I attached a ropdown in the GridView OnRowCreated event and set the autopostback property of the dropdown to true. Now I want to handle this index changed event of tje dropdown on the page where I'm using this custom control. I tried using Delegate and event but I got event null in dropdown index changed event.
public delegate void Chnageme(int inData);
public event Chnageme onChnageDropDown;
protected override void OnRowCreated(GridViewRowEventArgs e)
{
if (this.AllowPaging == true)
{
if (e.Row.RowType == DataControlRowType.Pager)
{
DropDownList ddlPage = new DropDownList();
ddlPage.Items.Add(new ListItem("10", "10"));
ddlPage.Items.Add(new ListItem("100", "100"));
ddlPage.AutoPostBack = true;
ddlPage.SelectedIndexChanged += new EventHandler(ddlPage_SelectedIndexChanged);
TableCell cellLeft = new TableCell();
cellLeft.HorizontalAlign = HorizontalAlign.Left;
cellLeft.Controls.Add(ddlPage);
}
}
}
void ddlPage_SelectedIndexChanged(object sender, EventArgs e)
{
//Found null
onChnageDropDown(Convert.ToInt32(((DropDownList)sender).SelectedValue));
}