D
Damien
Hi guys,
I'm trying to learn ASP.NET and got a problem with DroDownList...
SelectedIndexChanged doesn't fire.
Maybe you'll be able to suggest something.
I think it may be connected with the fact I fill this list dynamically.
I use the following code:
--presentation--
<%@ Page Language="C#" MasterPageFile="~/Site.master"
AutoEventWireup="true" CodeFile="index.aspx.cs"
Inherits="PagingAndSorting_index" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent"
Runat="Server">
<br />
<asp:Label ID="PageInfo" runat="server"
Text="Label"></asp:Label> <aspropDownList ID="PageList"
runat="server" AutoPostBack="True"
OnSelectedIndexChanged="PageList_SelectedIndexChanged">
</aspropDownList><br />
<br />
<asp:GridView ID="Products" runat="server"
AutoGenerateColumns="False" DataKeyNames="ProductID"
DataSourceID="ObjectDataSource1" AllowPaging="True"
OnDataBound="Products_DataBound">
<Columns>
<asp:BoundField DataField="ProductName" HeaderText="Product
Name" SortExpression="ProductName" />
<asp:BoundField DataField="CategoryName"
HeaderText="Category" ReadOnly="True" SortExpression="CategoryName" />
<asp:BoundField DataField="SupplierName"
HeaderText="Supplier" ReadOnly="True" SortExpression="SupplierName" />
<asp:BoundField DataField="UnitPrice" HeaderText="Price"
SortExpression="UnitPrice" />
<asp:CheckBoxField DataField="Discontinued"
HeaderText="Discontinued" SortExpression="Discontinued" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetProducts"
TypeName="ProductsBLL"></asp:ObjectDataSource>
</asp:Content>
---------------
-----logic----
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class PagingAndSorting_index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Products_DataBound(object sender, EventArgs e)
{
PageInfo.Text = string.Format("Page {0}/{1}",
Products.PageIndex + 1, Products.PageCount);
PageList.Items.Clear();
for (int i = 0; i < Products.PageCount; i++)
{
ListItem pageListItem = new ListItem(string.Concat("Go to
page: ", i + 1), i.ToString());
PageList.Items.Add(pageListItem);
if (i == Products.PageIndex)
pageListItem.Selected = true;
}
}
protected void PageList_SelectedIndexChanged(object sender,
EventArgs e)
{
Products.PageIndex = Convert.ToInt32(PageList.SelectedValue);
}
}
I'm trying to learn ASP.NET and got a problem with DroDownList...
SelectedIndexChanged doesn't fire.
Maybe you'll be able to suggest something.
I think it may be connected with the fact I fill this list dynamically.
I use the following code:
--presentation--
<%@ Page Language="C#" MasterPageFile="~/Site.master"
AutoEventWireup="true" CodeFile="index.aspx.cs"
Inherits="PagingAndSorting_index" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent"
Runat="Server">
<br />
<asp:Label ID="PageInfo" runat="server"
Text="Label"></asp:Label> <aspropDownList ID="PageList"
runat="server" AutoPostBack="True"
OnSelectedIndexChanged="PageList_SelectedIndexChanged">
</aspropDownList><br />
<br />
<asp:GridView ID="Products" runat="server"
AutoGenerateColumns="False" DataKeyNames="ProductID"
DataSourceID="ObjectDataSource1" AllowPaging="True"
OnDataBound="Products_DataBound">
<Columns>
<asp:BoundField DataField="ProductName" HeaderText="Product
Name" SortExpression="ProductName" />
<asp:BoundField DataField="CategoryName"
HeaderText="Category" ReadOnly="True" SortExpression="CategoryName" />
<asp:BoundField DataField="SupplierName"
HeaderText="Supplier" ReadOnly="True" SortExpression="SupplierName" />
<asp:BoundField DataField="UnitPrice" HeaderText="Price"
SortExpression="UnitPrice" />
<asp:CheckBoxField DataField="Discontinued"
HeaderText="Discontinued" SortExpression="Discontinued" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetProducts"
TypeName="ProductsBLL"></asp:ObjectDataSource>
</asp:Content>
---------------
-----logic----
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class PagingAndSorting_index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Products_DataBound(object sender, EventArgs e)
{
PageInfo.Text = string.Format("Page {0}/{1}",
Products.PageIndex + 1, Products.PageCount);
PageList.Items.Clear();
for (int i = 0; i < Products.PageCount; i++)
{
ListItem pageListItem = new ListItem(string.Concat("Go to
page: ", i + 1), i.ToString());
PageList.Items.Add(pageListItem);
if (i == Products.PageIndex)
pageListItem.Selected = true;
}
}
protected void PageList_SelectedIndexChanged(object sender,
EventArgs e)
{
Products.PageIndex = Convert.ToInt32(PageList.SelectedValue);
}
}