designer.cs不会自动生成任何内容

时间:2013-07-24 22:18:05

标签: c# asp.net gridview

为了抓住你,只是为了让你知道我无法相信这个简单的任务有多难。所以这就是我想要做的。我在名为Clients.aspx的页面上有一个数据绑定GridView(绑定到MySQL数据库)。我正在尝试使用“AutoGenerateSelectButton =”True“”生成的选择按钮将用户移动到另一个页面(页面称为EditClient.aspx)并允许它们从MySQL中提取所有数据。但我需要告诉EditClient.aspx页面要查看哪个键,所以我想使用“Response.Redirect(”EditClient.aspx?ID =“+ GridView1.SelectedDataKey.ToString())”。该代码位于一个名为OnRowSelected的函数中,该函数与“OnSelectedIndexChanged =”OnRowSelected“”相关联。

所以这是我的问题。代码有意义,应该正常工作吗?不。 Clients.aspx.designer.cs似乎并不像它应该那样自动生成所有需要的东西。我甚至尝试删除它并右键单击Clients.aspx>转换为Web应用程序,但生成相同的废话。我没有经验,所以我不能硬编码必要的。所以现在我遇到了错误“对象引用没有设置为对象的实例”。

如果你们要么告诉我如何硬编码,或者如何让我的项目开始自动生成我继续我的小项目所需的东西,那将会很棒。谢谢!以下是自己看的代码!:

Clients.aspx:

<%@ Page Title="Client Database" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="True"  CodeBehind="Clients.aspx.cs" Inherits="Client_Database.Clients" %>

<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
    <section class="featured">
        <asp:LoginView ID="LoginView1" runat="server" ViewStateMode="Disabled">
             <AnonymousTemplate>
             <div class="content-wrapper">
            <hgroup class="title">
                <h1>Please sign in to access the client database.</h1>
            </hgroup>
            Sign in by clicking the &quot;Log in&quot; button at the top right of the page.</div>
             </AnonymousTemplate>
             <LoggedInTemplate>
                 <div class="content-wrapper">
            <hgroup class="title">
                <h1>Industrial Andons Client Database.</h1>
            </hgroup>
            <asp:GridView ID="GridView1" runat="server" GridLines="None" AllowSorting="True" OnSelectedIndexChanged="OnRowSelected" AutoGenerateColumns="False" DataSourceID="MainSource" Font-Size="XX-Small" PageSize="100" Width="899px" CellPadding="4" ForeColor="#333333" AutoGenerateSelectButton="True" DataKeyNames="idMainTable">
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                <Columns>
                    <asp:BoundField DataField="CompanyName" HeaderText="Company" SortExpression="CompanyName" />
                    <asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
                    <asp:BoundField DataField="Contact1First" HeaderText="First" SortExpression="Contact1First" />
                    <asp:BoundField DataField="Contact1Last" HeaderText="Last" SortExpression="Contact1Last" />
                    <asp:BoundField DataField="Contact1DateofLastContact" HeaderText="Last Contact" SortExpression="Contact1DateofLastContact" />
                    <asp:BoundField DataField="Contact1DateofLastAttempt" HeaderText="LastAttempt" SortExpression="Contact1DateofLastAttempt" />
                    <asp:BoundField DataField="TrialEndDate" HeaderText="Trial End" SortExpression="TrialEndDate" />
                    <asp:BoundField DataField="FollowUpDate" HeaderText="Follow Up" SortExpression="FollowUpDate" />
                </Columns>
                <EditRowStyle BackColor="#999999" Wrap="False" />
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <HeaderStyle Font-Size="XX-Small" BackColor="#5D7B9D" BorderStyle="Ridge" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <RowStyle BorderStyle="Ridge" BackColor="#F7F6F3" Wrap="False" ForeColor="#333333" />
                <SelectedRowStyle BackColor="#E2DED6" BorderStyle="Double" Font-Bold="True" ForeColor="#333333" />
                <SortedAscendingCellStyle BackColor="#E9E7E2" />
                <SortedAscendingHeaderStyle Font-Bold="True" Font-Overline="True" BackColor="#506C8C" />
                <SortedDescendingCellStyle BackColor="#FFFDF8" />
                <SortedDescendingHeaderStyle Font-Underline="True" BackColor="#6F8DAE" />
            </asp:GridView>
                     <asp:SqlDataSource ID="MainSource" runat="server" ConnectionString="<%$ ConnectionStrings:indust24_custdB7rac3rCS5729d %>" ProviderName="<%$ ConnectionStrings:indust24_custdB7rac3rCS5729d.ProviderName %>" SelectCommand="SELECT idMainTable, CompanyName, State, Contact1First, Contact1Last, TrialEndDate, FollowUpDate, Contact1DateofLastContact, Contact1DateofLastAttempt FROM MainTable ORDER BY CompanyName"></asp:SqlDataSource>
        </div>
             </LoggedInTemplate>
         </asp:LoginView>
    </section>
</asp:Content>

Clients.aspx.designer.cs:

Clients.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Client_Database
{
    public partial class Clients : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void OnRowSelected(object sender, EventArgs e)
        {
            Response.Redirect("EditClient.aspx?ID=" + GridView1.SelectedDataKey.ToString());
        }
    }
}

0 个答案:

没有答案