SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist chiphunt1's Avatar
    Join Date
    Oct 2003
    Location
    louisville, ky
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SelectedIndexChanged not firing membership api

    I am using the asp.net 2.0 membership api. Everything is working correctly such as login, create user, etc. Now I'm trying to just use a gridview and make a select button to display the details of the selected user. From everything that I've read you can catch the SelectedIndexChanged on postback. My problem is the event never fires. I have put it breakpoints and the event never occurs. I can't figure out why? Thanks


    Code:
    html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server" action="RetrieveUsers.aspx">
        <div>
            <asp:GridView ID="UsersGridView" runat="server" DataKeyNames="UserName" AutoGenerateColumns="false" >
                <Columns>
                    
                    <asp:CommandField ShowSelectButton="true" ButtonType="Button" SelectText="select" />
                    <asp:BoundField DataField="UserName" HeaderText="Username" />
                    <asp:BoundField DataField="Email" HeaderText="Email" />
                    <asp:BoundField DataField="CreationDate" HeaderText="Creation Date" />
                 </Columns>
            </asp:GridView>
        </div>
       
        
        <p>
            Selected User:</p>
        
        <table border="1">
            <tr>
                <td>
                    User Name:</td>
                <td>
                    <asp:Label ID="UserNameLabel" runat="server" /></td>
            </tr>
            <tr>
                <td>
                    Email:</td>
                <td>
                    <asp:Label ID="EmailText" runat="server" /></td>
            </tr>
            
        </table>
          
            
        </form>
        
    </body>
    </html>
    Code:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    public partial class ManageUsers_RetrieveUsers : System.Web.UI.Page
    {
        MembershipUserCollection _MyUsers;
    
        protected void Page_Load(object sender, EventArgs e)
        {
            _MyUsers = Membership.GetAllUsers();
            UsersGridView.DataSource = _MyUsers;
    
            if (!this.IsPostBack)
            {
                UsersGridView.DataBind();
            }
        }
        
        protected void UsersGridView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (UsersGridView.SelectedIndex >= 0)
            {
                MembershipUser Current = _MyUsers[(string)UsersGridView.SelectedValue];
    
                UserNameLabel.Text = Current.UserName;
                EmailText.Text = Current.Email;
                //CreationLabel.Text = Convert.ToString(Current.CreationDate);
            }
        }
    Calm down -- it's only ones and zeroes

  2. #2
    SitePoint Evangelist chiphunt1's Avatar
    Join Date
    Oct 2003
    Location
    louisville, ky
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind, I figured out the problem. I needed to set the OnSelectedIndexChanged attribute correctly.

    Code:
     <asp:GridView ID="UsersGridView" runat="server" AutoGenerateColumns="false" AutoGenerateSelectButton="true"
                DataKeyNames="UserName" AllowPaging="true" AllowSorting="true" OnSelectedIndexChanged="UsersGridView_SelectedIndexChanged">
    Calm down -- it's only ones and zeroes


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •