Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Error:ASP.default2; does not contain a definition for gv_SelectedIndexChanged; and no extension method gv_SelectedIndexChanged accepting a first argument of type ASP.default2_aspx could be found (are you missing a using directive or an assembly reference?)

this is my aspx code....

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <asp:GridView runat="server" ID="gv" AutoGenerateColumns="False"
          onrowdatabound="gv_RowDataBound" CellPadding="4" ForeColor="#333333"
            GridLines="None" onselectedindexchanged="gv_SelectedIndexChanged" Width="188px">
          <AlternatingRowStyle BackColor="White" />
          <Columns>
              <asp:TemplateField>
                  <HeaderTemplate>
                      <asp:Label runat="server" ID="header" Text="Month"></asp:Label>
                  </HeaderTemplate>
                  <ItemTemplate>
                      <asp:Label runat="server" ID="lblMonth" Text='<%#Eval("Month")%>'></asp:Label>
                  </ItemTemplate>
              </asp:TemplateField>
              <asp:TemplateField>
                  <HeaderTemplate>
                      <asp:Label runat="server" ID="Day"></asp:Label>
                  </HeaderTemplate>
                  <ItemTemplate>
                      <asp:DropDownList runat="server" ID="drpDay" >
                      </asp:DropDownList>
                  </ItemTemplate>
              </asp:TemplateField>
          </Columns>
          <EditRowStyle BackColor="#2461BF" />
          <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
          <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
          <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
          <RowStyle BackColor="#EFF3FB" />
          <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
          <SortedAscendingCellStyle BackColor="#F5F7FB" />
          <SortedAscendingHeaderStyle BackColor="#6D95E1" />
          <SortedDescendingCellStyle BackColor="#E9EBEF" />
          <SortedDescendingHeaderStyle BackColor="#4870BE" />
      </asp:GridView></div>
    </form>
</body>
</html>




this is my aspx.cs 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;

public partial class Default2 : System.Web.UI.Page
{
    public DataTable dtDay = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //Creating static datatable
            DataTable dt = new DataTable();
            dt.Columns.Add("month");

            //Adding rows
            dt.Rows.Add("January");
            dt.Rows.Add("February");
            dt.Rows.Add("March");
            dt.Rows.Add("April");
            dt.Rows.Add("May");
            dt.Rows.Add("June");
            dt.Rows.Add("July");
            dt.Rows.Add("August");
            dt.Rows.Add("September");
            dt.Rows.Add("October");
            dt.Rows.Add("November");
            dt.Rows.Add("December");

            //Binding to grid
            gv.DataSource = dt;
            gv.DataBind();

        }
    }


    protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DropDownList drpDay = (DropDownList)e.Row.FindControl("drpDay");
            drpDay.DataSource = dtDay;
            drpDay.DataTextField = "Day";
            drpDay.DataValueField = "Day";
            drpDay.DataBind();

            drpDay.SelectedIndex = e.Row.RowIndex;
        }
        else if (e.Row.RowType == DataControlRowType.Header)
        {
            //Creating static datatable
            dtDay.Columns.Add("Day");
            //Adding rows
            dtDay.Rows.Add("1");
            dtDay.Rows.Add("2");
            dtDay.Rows.Add("3");
            dtDay.Rows.Add("4");
            dtDay.Rows.Add("5");
            dtDay.Rows.Add("6");
            dtDay.Rows.Add("7");
            dtDay.Rows.Add("8");
            dtDay.Rows.Add("9");
            dtDay.Rows.Add("10");
            dtDay.Rows.Add("11");
            dtDay.Rows.Add("12");
            dtDay.Rows.Add("13");
            dtDay.Rows.Add("14");
            dtDay.Rows.Add("15");
            dtDay.Rows.Add("16");
            dtDay.Rows.Add("17");
            dtDay.Rows.Add("18");
            dtDay.Rows.Add("19");
            dtDay.Rows.Add("20");
            dtDay.Rows.Add("21");
            dtDay.Rows.Add("22");
            dtDay.Rows.Add("23");
            dtDay.Rows.Add("24");
            dtDay.Rows.Add("25");
            dtDay.Rows.Add("26");
            dtDay.Rows.Add("27");
            dtDay.Rows.Add("28");
            dtDay.Rows.Add("29");
            dtDay.Rows.Add("30");
        }
    }
}
Posted
Updated 9-Feb-12 20:09pm
v2
Comments
Rajeev Jayaram 10-Feb-12 2:11am    
Hint: Quote from your question "Are you missing a using directive or an assembly reference?"
rockpune 10-Feb-12 2:13am    
now wat i have to do
rockpune 10-Feb-12 2:17am    
Server Error in '/Bind dropdwnlist in gridview' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1061: 'ASP.default2_aspx' does not contain a definition for 'gv_SelectedIndexChanged' and no extension method 'gv_SelectedIndexChanged' accepting a first argument of type 'ASP.default2_aspx' could be found (are you missing a using directive or an assembly reference?)

Source Error:

Line 11: <div>
Line 12:
Line 13: <asp:GridView runat="server" ID="gv" AutoGenerateColumns="False"
Line 14: onrowdatabound="gv_RowDataBound" CellPadding="4" ForeColor="#333333"
Line 15: GridLines="None" onselectedindexchanged="gv_SelectedIndexChanged" Width="188px">

What to do: either start going in for programming or give up this branch of engineering. So far, what are you doing is something opposite to programming, which is all about generalization and abstractions.

A software engineer will never ever repeat the line like dtDay.Rows.Add("1"); 30 times! If you know what to do instead, it's kind of quite difficult to explain in a quick answer. Ever heard of methods, parameters, loops, etc.?

Maybe this can help you: http://en.wikipedia.org/wiki/Don%27t_repeat_yourself[^]?

At this moment, no way you should develop ASP.NET, UI or any other "advanced" application. Your only chance is starting with simple exercises using tiny console applications, until you get a grasp on how to do programming in principle. Right now, what are you doing is just a waste of time. Grab an elementary book on programming, language and .NET and go ahead.

Please don't get offended and understand I telling this to really help you.

See also:
using and meaningful of Framework[^],
http://norvig.com/21-days.html[^].

—SA
 
Share this answer
 
v2
Comments
Rajeev Jayaram 10-Feb-12 3:18am    
5!
Sergey Alexandrovich Kryukov 10-Feb-12 3:20am    
Thank you, Rajeev.
Such posts often gets down-voted; so it's a pleasure to talk with somebody who understands things.
--SA
Rajeev Jayaram 10-Feb-12 13:48pm    
You're welcome, SA.

Quote from your link http://norvig.com/21-days.html: "One possible point is that you have to learn a tiny bit of something because you need to interface with an existing tool to accomplish a specific task. But then you're not learning how to program; you're learning to accomplish that task."

It's an awesome piece of advice that should definitely help OP and everyone else for that matter.
Hi,

As I see in you code clearly no gv_SelectedIndexChanged function/method has been created. I advise you to create one...
Example:
C#
protected void gv_SelectedIndexChanged(object sender, EventArgs e)
{
    // Your code here?...

}



You may do it on Disign page mode. Right click your grid then goto Properties, Event then
click on SelectedIndexChanged.


Happy coding...
 
Share this answer
 
v3
Comments
rockpune 10-Feb-12 2:18am    
thank u
Al Moje 10-Feb-12 2:28am    
Please vote if its help you...

Welcome and Regards,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900