0
我無法獲取OnRowCommand開火。什麼看起來不對?這是爲了顯示來自sql server的數據庫,每個行都有鏈接。它是建立在C#使用MVC和visual studio 2010我不知道什麼可能是錯誤的程序,我已經在此頁面和site.master頁面上啓用ViewStateMode,並試圖編輯它的方式太長,有什麼看起來不對?OnRowCommand未開火
順便說一下,這是我們第一次使用c#MVC或asp.net,所以代碼在這方面可能有點草率。
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<Teamsone.Models.Student>" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Registration
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<form id="form1" runat="server">
<h2>Classes offered for Next Semester [Spring 2012]</h2>
<script runat="server">
protected void GridView1_RowCommand(Object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[index];
// Create a new ListItem object for the contact in the row.
ListItem item = new ListItem();
item.Text = "weeeee!";
ContactsListBox.Items.Add(item);
}
</script>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
OnRowCommand="GridView1_RowCommand" allowpaging="true" DataKeyNames="SectionKey"
DataSourceID="SqlDataSource1" EnableViewState = "true">
<Columns>
<asp:BoundField DataField="FacultyKey" HeaderText="FacultyKey"
SortExpression="FacultyKey" />
<asp:BoundField DataField="SectionKey" HeaderText="SectionKey" ReadOnly="True"
SortExpression="SectionKey" />
<asp:BoundField DataField="CourseKey" HeaderText="CourseKey"
SortExpression="CourseKey" />
<asp:BoundField DataField="SectionDay" HeaderText="SectionDay"
SortExpression="SectionDay" />
<asp:BoundField DataField="SectionTime" HeaderText="SectionTime"
SortExpression="SectionTime" />
<asp:BoundField DataField="SectionSemester" HeaderText="SectionSemester"
SortExpression="SectionSemester" />
<asp:BoundField DataField="SectionYear" HeaderText="SectionYear"
SortExpression="SectionYear" />
<asp:BoundField DataField="ClassroomKey" HeaderText="ClassroomKey"
SortExpression="ClassroomKey" />
<asp:buttonfield buttontype="Link"
commandname="Add"
text="Add"/>
</Columns>
</asp:GridView>
<asp:listbox id="ContactsListBox" runat="server" Height="200px" Width="200px"/>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [NextCourse]"></asp:SqlDataSource>
</form>
</asp:Content>
到目前爲止,它看起來並不像你對我實際上是使用* * MVC,你似乎陷入了webforms模式。 –
你可能想閱讀MVC,因爲(就像Anthony Pegram所說的那樣),它看起來像是在嘗試使用webforms而不是MVC。查看http://www.asp.net/mvc/tutorials –