C# 使用on select添加数据
我没有什么问题,不明白为什么它不起作用, 我试图做的是向下滚动我的用户列表,这些用户还没有使用配置文件激活,然后将他们添加到UserProfile表中,并为他们提供一个配置文件。我认为代码是正确的,但还不完全正确 我仍然是一个错误 错误 错误1“ASP.account\u userswithoutprofile\u aspx”不包含“Add\u Prof\u SelectedIndexChanged”的定义,并且找不到接受类型为“ASP.account\u userswithoutprofile\u aspx”的第一个参数的扩展方法“Add\u Prof\u SelectedIndexChanged”(是否缺少using指令或程序集引用?) 设计规范C# 使用on select添加数据,c#,asp.net,sql,database,onselect,C#,Asp.net,Sql,Database,Onselect,我没有什么问题,不明白为什么它不起作用, 我试图做的是向下滚动我的用户列表,这些用户还没有使用配置文件激活,然后将他们添加到UserProfile表中,并为他们提供一个配置文件。我认为代码是正确的,但还不完全正确 我仍然是一个错误 错误 错误1“ASP.account\u userswithoutprofile\u aspx”不包含“Add\u Prof\u SelectedIndexChanged”的定义,并且找不到接受类型为“ASP.account\u userswithoutprofile
<%@ 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>
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();
}
}
Userwithoutprofile designer
<%@ 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>
}
}
首先,类型“Default2”已包含“添加用户”的定义
问题1:您已经在Default2
页面中使用ID
Add\u User
创建了另一个控件
解决方案1:将该控件的ID
正确重命名为不同的ID
second The name 'Add_Prof' does not exist in the current context
问题2:我认为您已将Add\u Prof
gridview代码复制到Add\u User
gridview中。这就是它无法在Default2
页面中识别Add\u Prof
gridview的原因
试试这个:
设计代码:
<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
页面的完整设计代码,我们将为您提供更好的帮助
首先,类型“Default2”已包含“添加用户”的定义
问题1:您已经在Default2
页面中使用ID
Add\u User
创建了另一个控件
解决方案1:将该控件的ID
正确重命名为不同的ID
second The name 'Add_Prof' does not exist in the current context
问题2:我认为您已将Add\u Prof
gridview代码复制到Add\u User
gridview中。这就是它无法在Default2
页面中识别Add\u Prof
gridview的原因
试试这个:
设计代码:
<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
页面的完整设计代码,我们将为您提供更好的帮助
首先,类型“Default2”已包含“添加用户”的定义
问题1:您已经在Default2
页面中使用ID
Add\u User
创建了另一个控件
解决方案1:将该控件的ID
正确重命名为不同的ID
second The name 'Add_Prof' does not exist in the current context
问题2:我认为您已将Add\u Prof
gridview代码复制到Add\u User
gridview中。这就是它无法在Default2
页面中识别Add\u Prof
gridview的原因
试试这个:
设计代码:
<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
页面的完整设计代码,我们将为您提供更好的帮助
首先,类型“Default2”已包含“添加用户”的定义
问题1:您已经在Default2
页面中使用ID
Add\u User
创建了另一个控件
解决方案1:将该控件的ID
正确重命名为不同的ID
second The name 'Add_Prof' does not exist in the current context
问题2:我认为您已将Add\u Prof
gridview代码复制到Add\u User
gridview中。这就是它无法在Default2
页面中识别Add\u Prof
gridview的原因
试试这个:
设计代码:
<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
页面的完整设计代码,我们可以为您提供更好的帮助。查看designer.cs文件,查看您是否有两次添加用户定义。你能从designer.cs发布代码吗?你重新命名了gridView吗?你能发布完整的设计代码吗?简单回答一下,因为你错过了名字的意义!!这是类似iTunes的论坛网站,我们不使用“谢谢”或“感谢任何帮助”或签名。请看“.好的,John明白了,我会让它更专业,不再感谢你查看designer.cs文件,看看你是否添加了两次用户定义。你能发布designer.cs中的代码吗?你重命名了gridView吗?你能发布完整的设计代码吗?简单回答一下,因为你没有名字的意思!!这是类似iTunes的论坛网站,我们不使用”“谢谢”,或“感谢您的帮助”,或在.See上签名。好的,John理解,我会让它更专业,不再感谢查看designer.cs文件,查看您是否添加了两次用户定义。你能从designer.cs发布代码吗?你重新命名了gridView吗?你能发布完整的设计代码吗?简单回答一下,因为你错过了名字的意义!!这是类似iTunes的论坛网站,我们不使用“谢谢”或“感谢任何帮助”或签名。请参阅“.好的,John明白了,我会让它更专业,不再感谢查看designer.cs文件,看看您是否添加了两次用户定义的。您可以发布designer.cs中的代码吗?您是否重命名了gridView?您可以发布完整的设计代码吗?简单