A
Andrew Robinson
I am attempting to better automate a Pager Template within a GridView. I am
succesfully skinning a Drop Down List withing my control (the DDL is added
to my control). I correctly populate the item list that corresponds with the
number of pages, but I am unable to wire up the Selected Index Changed
event. Auto PostBack is set to true and the page is posting back when the
DDL is selected / chaged, but the event is never being called.
Any ideas?
Secon question: how can I dynamically generate the pager template that
contains the DDL?
Thanks!
public class DataGridView : GridView {
protected override void OnRowDataBound(GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.Pager) {
LoadPagerTemplate(e.Row);
}
base.OnRowDataBound(e);
}
private void LoadPagerTemplate(GridViewRow row) {
DropDownList dropDownListPager =
(DropDownList)row.FindControl("DropDownListPager");
if (dropDownListPager != null) {
for (int i = 1; i <= this.PageCount; i++) {
dropDownListPager.Items.Add(new ListItem(i.ToString(),
i.ToString()));
}
dropDownListPager.SelectedIndexChanged += new
EventHandler(DropDownListPager_SelectedIndexChanged);
}
}
public void DropDownListPager_SelectedIndexChanged(object sender,
EventArgs e) {
this.PageIndex = ((DropDownList)sender).SelectedIndex; // <- this
is never reached when I change the DDL.
this.DataBind();
}
}
succesfully skinning a Drop Down List withing my control (the DDL is added
to my control). I correctly populate the item list that corresponds with the
number of pages, but I am unable to wire up the Selected Index Changed
event. Auto PostBack is set to true and the page is posting back when the
DDL is selected / chaged, but the event is never being called.
Any ideas?
Secon question: how can I dynamically generate the pager template that
contains the DDL?
Thanks!
public class DataGridView : GridView {
protected override void OnRowDataBound(GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.Pager) {
LoadPagerTemplate(e.Row);
}
base.OnRowDataBound(e);
}
private void LoadPagerTemplate(GridViewRow row) {
DropDownList dropDownListPager =
(DropDownList)row.FindControl("DropDownListPager");
if (dropDownListPager != null) {
for (int i = 1; i <= this.PageCount; i++) {
dropDownListPager.Items.Add(new ListItem(i.ToString(),
i.ToString()));
}
dropDownListPager.SelectedIndexChanged += new
EventHandler(DropDownListPager_SelectedIndexChanged);
}
}
public void DropDownListPager_SelectedIndexChanged(object sender,
EventArgs e) {
this.PageIndex = ((DropDownList)sender).SelectedIndex; // <- this
is never reached when I change the DDL.
this.DataBind();
}
}