Monday, March 12, 2012

how to convert objectdatasource to dataView?

hi there...does anyone run into a problem where the objectdatasource cannot be casting into dataview? it aleays works for me except for this time

.csDataView dv = (DataView)objSubCategoriesByUserPermissions.Select();.aspx<asp:ObjectDataSource ID="objSubCategoriesByUserPermissions" runat="server" SelectMethod="GetCategoryByUserPermissions" TypeName="MB.TheBeerHouse.BLL.Articles.Category"> <SelectParameters> <asp:QueryStringParameter Name="articleID" QueryStringField="ID" DefaultValue="-1" /> <asp:ProfileParameter Name="username" PropertyName="username" /> </SelectParameters> </asp:ObjectDataSource> <br /> <asp:SqlDataSource ID="sdcAllCategories" runat="server" ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString%>" SelectCommand="SELECT CategoryID, Title FROM tbh_Categories WHERE (visible = 1) AND (ParentID IS NULL)"> </asp:SqlDataSource>

Unable to cast object of type 'System.Object[]' to type 'System.Data.DataView'.

Hi

ObjectDataSource.select() must return one of the types listed below:

IEnumerable

TheIEnumerable is returned by theSelect method.

DataTable

ADataView is created by using theDataTable and returned by theSelect method.

DataView

TheDataView is returned by theSelect method.

DataSet

The firstDataTable of theDataSet is extracted and aDataView is created and returned by theSelect method.

Object

The object is wrapped in a one-elementIEnumerable collection and returned by theSelect method.

Here is a similar thread that may give you clue:http://forums.asp.net/thread/1491464.aspx

For details about ObjectDataSource.select() seehttp://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.select.aspx

Hope this helps.


thank it does.

Labels: , , , , , , ,

How to convert from UserId to UserName in GridView?

i am using membership, and my GridView are using by choosing ObjectDataSource , In my ObjectDataSource i am using UserId, but when show the GridView i want the UserId changer UserName.How to do it? For example my some code,

<asp:TemplateField HeaderText="UserId"><ItemTemplate><%#Eval("UserId")%></ItemTemplate></asp:TemplateField>

You could write method that calls

MembershipUser u =Membership.GetUser(userID);.

username = u.UserName

Then call it from the template with <%# (String) MyGetUserNameMethod(String userid) %>

(declare the function protected string MyGetUseNameMethod in your code behind class)


Dear Sir,

Sorry i still can not understand!


hi

try this

<asp:TemplateField> <ItemTemplate><%#Membership.GetUser(Eval("UserId")).UserName%> </ItemTemplate> </asp:TemplateField>

Dear Sir,

Still can not!


hi

just replace your code with the one i gave you

so delete your templateField column and put my code

man if you still dont understand ,

could you explain what is the things that makes you confused

thanks


Dear Sir,

Thank!!it working,Sorry Sir, maybe just now i am typing wrong, Now, i am no error, Finally Thank you Sir!!!

Labels: , , , , , , , ,

how to convert a row in gridview to my business class DialUpRow generated by dataSet desig

I have GridView with: objectdatasource="objectdatasource1"

Objectdatasource1 is linked to my BLL (business layer with a dataset designer genrating: DialUpRow as an item of my datatable: DialupUpDataTable

I want to convert the selected row to my class: DialUpRow

I get the selected row using: myGRidView.SelectedIndex

But I don t know how to convert the grid row to my DialUpRow in order to get intellisence of my row properies (calss properties in code behind)

DataItem property of the GridViewRow would give the dataitem bound to the GridView. Below is a sample code. In the code, I haven't done any error checking, please ensure you do in your code.

Dim row as GridViewRow = GridView1.Rows(GridView1.SelectedIndex)if row isnot nothing thenDim drow as DialUpRow =CType(row.DataItem, DialUpRow)endif

Labels: , , , , , , , , , , , , , , , , ,