Monday, March 26, 2012

NEWBIE: problem populating a GridView

ASP.NET 2.0

I have a GridView control in my webpage. In this GridView's
gridUsers_RowDataBound am I having problem populating the controls with info
from the datasource -

This code is the problem:
MembershipUser user = (MembershipUser)e.Row.DataItem;
The user object doesn't get a MembershipUser value, it gets the value NULL.

Here are some of the code from my webpage so can get an overview of what I'm
doing:
<asp:GridView ID="gridUsers"
runat="server"
AutoGenerateColumns="false"
OnRowDataBound="gridUsers_RowDataBound" >

protected void Page_Load(object sender, EventArgs e)
{
MembershipUserCollection allUsers = Membership.GetAllUsers();
gridUsers.DataSource = allUsers;
gridUsers.DataBind();
}

protected void gridUsers_RowDataBound(object o, GridViewRowEventArgs e)
{
MembershipUser user = (MembershipUser)e.Row.DataItem; **** < this code
don't work
ProfileCommon userProfile = Profile.GetProfile(user.UserName);
/*
Here I will put code that manually populate the columns in the
GridView with info from the Profile object
*/
}

any suggestions on what I should do to populate the user object with the
MembershipUser value?

JeffFixed, I had forgotten this if statement:
if (e.Row.RowType == DataControlRowType.DataRow)

"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:eXxSBdzWHHA.4860@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

ASP.NET 2.0
>
I have a GridView control in my webpage. In this GridView's
gridUsers_RowDataBound am I having problem populating the controls with
info from the datasource -
>
This code is the problem:
MembershipUser user = (MembershipUser)e.Row.DataItem;
The user object doesn't get a MembershipUser value, it gets the value
NULL.
>
Here are some of the code from my webpage so can get an overview of what
I'm doing:
<asp:GridView ID="gridUsers"
runat="server"
AutoGenerateColumns="false"
OnRowDataBound="gridUsers_RowDataBound" >
>
protected void Page_Load(object sender, EventArgs e)
{
MembershipUserCollection allUsers = Membership.GetAllUsers();
gridUsers.DataSource = allUsers;
gridUsers.DataBind();
}
>
protected void gridUsers_RowDataBound(object o, GridViewRowEventArgs e)
{
MembershipUser user = (MembershipUser)e.Row.DataItem; **** < this code
don't work
ProfileCommon userProfile = Profile.GetProfile(user.UserName);
/*
Here I will put code that manually populate the columns in the
GridView with info from the Profile object
*/
}
>
any suggestions on what I should do to populate the user object with the
MembershipUser value?
>
Jeff
>

0 comments:

Post a Comment