这下面的代码中的错误任何一个解决PLZ [英] error in this below code any one solve plz

查看:57
本文介绍了这下面的代码中的错误任何一个解决PLZ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误:ASP.default2;不包含gv_SelectedIndexChanged的定义;并且找不到可以接受类型为ASP.default2_aspx的第一个参数的扩展方法gv_SelectedIndexChanged(您是否缺少using指令或程序集引用?)

这是我的aspx代码....

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

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





这是我的aspx.cs代码....





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");
        }
    }
}

推荐答案

要做的事情:要么开始从事编程工作,要么放弃这一工程学分支.到目前为止,您在做什么与编程相反,而编程则与泛化和抽象有关.

软件工程师将永远不会重复执行dtDay.Rows.Add("1");这样的行30次!如果您知道该怎么做,那么在快速回答中就很难解释.是否听说过方法,参数,循环等?

也许这可以帮助您: http://en.wikipedia.org/wiki/Don%27t_repeat_yourself [ ^ ]?

目前,您不应该开发ASP.NET,UI或任何其他高级"应用程序.您唯一的机会是从使用小型控制台应用程序进行简单练习开始,直到您掌握了原则上如何进行编程为止.现在,您在做什么只是浪费时间.获取有关编程,语言和.NET的基础书籍,然后继续.

请不要生气,明白我告诉你这确实对您有帮助.

另请参见:
框架的使用和意义 [ http://norvig.com/21-days.html [
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




正如我在您的代码中看到的那样,显然没有创建gv_SelectedIndexChanged函数/方法.我建议您创建一个...
示例:
Hi,

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

}




您可以在设计页面模式下执行此操作.右键单击网格,然后转到属性",事件",然后
点击SelectedIndexChanged.


编码愉快...




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


Happy coding...


这篇关于这下面的代码中的错误任何一个解决PLZ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆