Adding data using on select

166 views Asked by At

I am having few problems and do not understand why it is not working, What i am trying to do is scroll down my list of users that have not been activated with a profile then add them to UserProfile table given them a profile. I think the code is right but not quite there yet.

I am still a error

error

Error 1 'ASP.account_userswithoutprofile_aspx' does not contain a definition for 'Add_Prof_SelectedIndexChanged' and no extension method 'Add_Prof_SelectedIndexChanged' accepting a first argument of type 'ASP.account_userswithoutprofile_aspx' could be found (are you missing a using directive or an assembly reference?)

Design code

    <%@ 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# code

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>
        &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>



}
1

There are 1 answers

0
Sudhakar Tillapudi On BEST ANSWER

first The type 'Default2' already contains a definition for 'Add_User'

Problem 1: You have already created another control in Default2 page with ID Add_User.

Solution 1: Rename that control ID properly to different ID.

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

Problem 2: i think you have copied Add_Prof gridview code into Add_User gridview.thats why it is unable to identify the Add_Prof Gridview in Default2 page

Try This:

Design Code:

<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>

Code Behind:

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

Suggestion: please follow the proper naming conventions (relative names) for controls so that you won't get confusions.

Note: if you can share the complete design code of Default2 page we could you help you much better.