Если вы хотите посчитать ID за год, попробуйте использовать -
df[['ID','Year']].groupby('Year').count()
или-
df[['ID','Year']].groupby('Year').agg('count')
Измените переменные, чтобы получить результат.
Instead of using AppendDataboundItems='true'
(which will cause the problem you are talking about), respond to the DataBound
event for the DropDownList
and then add your "blank" item to the top of the list.
<asp:DropDownList runat="server" ID="MyList"
ondatabound="MyListDataBound"></asp:DropDownList>
Then in your code behind:
protected void MyListDataBound(object sender, EventArgs e)
{
MyList.Items.Insert(0, new ListItem("- Select -", ""));
}
<asp:DropDownList ID="DropDownList1" AppendDataBoundItems="true" runat="server"
DataSourceID="SqlDataSource1" DataTextField="state" DataValueField="state">
<asp:ListItem Text="(Select a State)" Value="" />
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:pubsConnectionString %>"
SelectCommand="SELECT DISTINCT [state] FROM [authors]">
</asp:SqlDataSource>
Вы, вероятно, связали этот DropDownList в коде. Поэтому не следует делать это снова после обратной передачи:
// probably in Page_Load method
if (!Page.IsPostBack)
{
// do data binding here
};
Вот идея.
В раскрывающемся списке есть свойство AutoPostBack
, установите для него значение true, а затем в коде вы помещаете весь метод привязки внутри if (! Page.IsPostBack)
. У меня это сработало.
с уважением.