Creating Custom Parameter Types for DataSource Controls in ASP.NET 2.0
I've posted in the past about how to create your own custom datasource controls using ASP.NET 2.0. One of the other cool new ASP.NET 2.0 extensibility points is the ability to create your own custom datasource parameter objects. These can then be used with any datasource control (including built-in ones like ObjectDataSource or SqlDataSource -- or any other custom ones). That way, you could write code like this (where I have a sortable, pagable GridView binding against a business object or DAL like this):
<asp:GridView ID="GridView1" runat="server" DataSourceID="DS1" AllowPaging="True" AllowSorting="True">
<Columns>
<asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="DS1" runat="server" SelectMethod="GetAllCategories" TypeName="NorthwindTableAdapters.CategoriesTableAdapter"
<SelectParameters>
<asp:QueryStringParameter Name="CategoryName" QueryStringFiled="CategoryName" />
<scottgu:MyCustomParam Name="Param2" SomeAttribute="SomeValue" />
</SelectParameters>
</asp:ObjectDataSource>
Note the "scottgu:MyCustomParam" parameter above in the <SelectParameters> collection -- this could implement whatever logic we want to generate the "Param2" value (for example: it could access a property on a page, access the user.identity.name value, or execute any code we want). This can be very useful when you have a lot of parameter types throughout projects that you want to re-use.
Fredrik Normen (who has a great ASP.NET blog!) has published a cool posting that shows how to implement parameters like the one above. You can read all about it here.
Update: Eilon Lipton (who is the ASP.NET developer who built many of the data controls) just posted a great blog entry on how to-do this here as well.
Hope this helps -- and special thanks to Fredrik for writing this entry.
Scott