Find total row count when databinding
This is a hard one to explain, so I'll just go with an example - I'm creating a databound datagrid where one column shows the priority ranking of each row, from 1 to the total number of rows. These will be presented as dropDownLists so that the user can select a new priority for each row.
I've created my own simple user control that creates a dropdownlist with options from 1-TotalRows and then sets the selected index based on the current priority of the item. I have a template column in my datagrid that calls the user control:
<asp:TemplateColumn SortExpression="Priority" HeaderText="Priority">
<ItemTemplate><uc1:myPriority CurrentPriority='<%# DataBinder.Eval(Container.DataItem, "Priority") %>' TotalRows="5" runat="server"></uc1:myPriority>
</ItemTemplate>
</asp:TemplateColumn>
As you can see, I need to pass two parameters into my usercontrol - the CurrentPriority, which I am easily getting from the current row, but also the TotalRows, which I have no idea how to find. DataBinder doesn't seem to have a way to let me find it here. If I do an .ItemCreated event in my codebehind, I'd be able to get the total number of rows, but I can't figure out a way to pass that as a parameter to my user control. I'm just looking for any way to accomplish this goal.
Thanks,
Julie
|