NEWBIE: problem populating a GridView

Discussion in 'ASP .Net' started by Jeff, Feb 28, 2007.

  1. Jeff

    Jeff Guest

    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
     
    Jeff, Feb 28, 2007
    #1
    1. Advertising

  2. Jeff

    Jeff Guest

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



    "Jeff" <> wrote in message
    news:...
    > 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
    >
     
    Jeff, Feb 28, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    8,863
    =?Utf-8?B?RWx0b24gVw==?=
    Mar 1, 2006
  2. =?Utf-8?B?YmlsbCB0aWU=?=

    problem populating gridView on dropDownList

    =?Utf-8?B?YmlsbCB0aWU=?=, Apr 26, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    614
    Vlad Iliescu
    Apr 27, 2006
  3. Mike P
    Replies:
    0
    Views:
    476
    Mike P
    Jun 2, 2006
  4. Replies:
    6
    Views:
    506
  5. Jeff

    Problem populating GridView!

    Jeff, Oct 11, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    354
    David R. Longnecker
    Oct 11, 2006
Loading...

Share This Page