ASP.NET - Object Data Source code behind

  • Thread starter Thread starter Izi
  • Start date Start date

Izi

Izi

Soldato
Joined
9 Dec 2007
Posts
2,718
I have a website where commenting will be allowed across multiple areas.I have created a control so that this commenting feature can be re-used.

I am using a listview for the comments, with an object data source. The object data source select params etc will change depending on the section.

PHP:
<asp:ObjectDataSource ID="objComments" runat="server" 
                    SelectMethod="GetComments" SelectCountMethod="GetCommentsCount" InsertMethod="PostComment"
                    TypeName="Messages.Messages"
                    EnablePaging="true" StartRowIndexParameterName="startRowIndex" MaximumRowsParameterName="maximumRows" >
                <SelectParameters>
                    <asp:QueryStringParameter DbType="Guid" Name="UserId" QueryStringField="UserId" />
                    <asp:Parameter Name="maximumRows" Type="Int32" />
                    <asp:Parameter Name="startRowIndex" Type="Int32" />
                </SelectParameters>
                <InsertParameters>
                    <asp:QueryStringParameter DbType="Guid" Name="RecipientId" QueryStringField="UserId" />
                    <asp:Parameter Type="Int32" Name="ParentCommentId" ConvertEmptyStringToNull="true" />
                    <asp:Parameter DbType="Object" Name="CommentType" DefaultValue="Friend" />
                </InsertParameters>
                </asp:ObjectDataSource>


As this will change, it needs to be done programmatically:

PHP:
ods.ID = "objComments";
        ods.TypeName = "Messages.Messages";
        ods.SelectMethod = "GetComments";
        ods.SelectCountMethod = "GetCommentsCount";
        ods.EnablePaging = true;
        ods.StartRowIndexParameterName = "startRowIndex";
        ods.MaximumRowsParameterName = "maximumRows";
        ods.InsertMethod = "PostComment";

        ods.SelectParameters.Add("maximumRows", TypeCode.Int32, "10");
        ods.SelectParameters.Add("startRowIndex", TypeCode.Int32, "0");
        ods.SelectParameters.Add("UserId", TypeCode.SByte, Users.GetCurrentUserId());

However, the TypeCode for UserId which is a GUID is not available, does anyone else know how I could pass this param?

Am i going in the right direction?
 
just thought, being completly stupid. Just have two normal Object data sources, then choose from code behind which one to bind the listview too. doh.

anyway, I'd still be interested to know how to add the select param of typr guid?
 
Last edited:
Back
Top Bottom