0

我遇到了一些问题,不明白为什么它不起作用,我想做的是向下滚动我的未使用配置文件激活的用户列表,然后将它们添加到 UserProfile 表中给他们一个配置文件。我认为代码是正确的,但还没有完全到位。

我还是一个错误

错误

错误 1“ASP.account_userswithoutprofile_aspx”不包含“Add_Prof_SelectedIndexChanged”的定义,并且找不到接受“ASP.account_userswithoutprofile_aspx”类型的第一个参数的扩展方法“Add_Prof_SelectedIndexChanged”(您是否缺少 using 指令或程序集引用?)

设计规范

    <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="UsersWithoutProfile.aspx.cs" Inherits="Default2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <p>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </p>
    <p>
         <asp:GridView ID="Add_Usertoprof" runat="server" AutoGenerateSelectButton="True"   
BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" 
CellPadding="3" GridLines="Vertical" 
OnSelectedIndexChanged="Add_User_SelectedIndexChanged">
        <AlternatingRowStyle BackColor="#DCDCDC" />
        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
        <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
        <SortedAscendingCellStyle BackColor="#F1F1F1" />
        <SortedAscendingHeaderStyle BackColor="#0000A9" />
        <SortedDescendingCellStyle BackColor="#CAC9C9" />
        <SortedDescendingHeaderStyle BackColor="#000065" />             
   </asp:GridView>

        <asp:Label ID="userlabel" runat="server" Text="Label"></asp:Label>
    </p>
    <p>
         <asp:Button ID="Button_adduser" runat="server" Text="Add User Profile" />
    </p>
</asp:Content>

C# 代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;

public partial class Default2 : System.Web.UI.Page
{
    DataTable dt = new DataTable();
    DataSet ds = new DataSet();
    OleDbDataAdapter da = new OleDbDataAdapter();
    OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\ASPNetDB.mdb;Persist Security Info=True");

    protected void Page_Load(object sender, EventArgs e)
    {
        user_profile_Add();
    }

    public void user_profile_Add()
    {
        {
            using (OleDbDataAdapter dataquer = new OleDbDataAdapter("SELECT * FROM asp_Users ", conn))
            {
                dataquer.Fill(dt);
            }
        }
        Add_Usertoprof.ShowHeader = true;
        Add_Usertoprof.DataSource = dt;
        Add_Usertoprof.DataBind();
        conn.Close();
        conn.Dispose();
    }

    protected void Add_User_SelectedIndexChanged(Object sender, EventArgs e)
    {
        GridViewRow row = Add_Usertoprof.SelectedRow;
        userlabel.Text = "Activate user" + " " + row.Cells[3].Text;
    }



    protected void Button_adduser_Click(object sender, EventArgs e)
    {
        OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\ASPNetDB.mdb;Persist Security Info=True");
        {
            var myquery = string.Format("INSERT INTO UserProfile (UserName");
            var row = Add_Usertoprof.SelectedRow;
            var title = row.Cells[1].Text;

            conn.Open();
            using (OleDbCommand cmd = new OleDbCommand(myquery, conn))
                cmd.ExecuteNonQuery();
            conn.Close();
            conn.Dispose();
        }
    }

没有个人资料设计师的用户

   <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="UsersWithoutProfile.aspx.cs" Inherits="Default2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <p>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </p>
    <p>
         <asp:GridView ID="Add_Usertoprof" runat="server" AutoGenerateSelectButton="True"   
BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" 
CellPadding="3" GridLines="Vertical" 
OnSelectedIndexChanged="Add_User_SelectedIndexChanged">
        <AlternatingRowStyle BackColor="#DCDCDC" />
        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
        <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
        <SortedAscendingCellStyle BackColor="#F1F1F1" />
        <SortedAscendingHeaderStyle BackColor="#0000A9" />
        <SortedDescendingCellStyle BackColor="#CAC9C9" />
        <SortedDescendingHeaderStyle BackColor="#000065" />             
   </asp:GridView>

        <asp:Label ID="userlabel" runat="server" Text="Label"></asp:Label>
    </p>
    <p>
         <asp:Button ID="Button_adduser" runat="server" Text="Add User Profile" />
    </p>
</asp:Content>



}
4

1 回答 1

3

首先“Default2”类型已经包含“Add_User”的定义

问题 1: 您已经在Default2页面中创建了另一个控件ID Add_User

解决方案 1:将该控件ID正确重命名为不同的ID.

second The name 'Add_Prof' does not exist in the current context

问题 2:Add_Prof我认为您已将gridview 代码复制到Add_Usergridview 中。这就是为什么它无法识别页面中的Add_ProfGridviewDefault2

尝试这个:

设计规范:

<asp:GridView ID="Add_User" runat="server" AutoGenerateSelectButton="True"   
BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" 
CellPadding="3" GridLines="Vertical" 
OnSelectedIndexChanged="Add_User_SelectedIndexChanged">
        <AlternatingRowStyle BackColor="#DCDCDC" />
        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
        <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
        <SortedAscendingCellStyle BackColor="#F1F1F1" />
        <SortedAscendingHeaderStyle BackColor="#0000A9" />
        <SortedDescendingCellStyle BackColor="#CAC9C9" />
        <SortedDescendingHeaderStyle BackColor="#000065" />             
   </asp:GridView>

代码背后:

 protected void Add_User_SelectedIndexChanged(Object sender, EventArgs e)
    {
        GridViewRow row = Add_User.SelectedRow;
        userlabel.Text = "Activate user"+" " + row.Cells[3].Text;
    }

建议: 请遵循正确的控件命名约定(相对名称),以免混淆。

注意:如果您可以分享Default2页面的完整设计代码,我们可以为您提供更好的帮助。

于 2013-12-22T17:30:40.110 回答