我遇到了一些问题,不明白为什么它不起作用,我想做的是向下滚动我的未使用配置文件激活的用户列表,然后将它们添加到 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>
</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>
</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>
}