日期:2014-05-17  浏览次数:20562 次

关于gridview自动编辑问题 想明白里面更新的具体实现方法
<%@ Page Title="" Language="C#" MasterPageFile="~/admin/AdminMaster.Master" AutoEventWireup="true" CodeBehind="CategoriesMan.aspx.cs" Inherits="UI1.admin.CategoriesMan" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
function SelectAll() {
var cbk = document.getElementById("cbkall");
var cbkson = document.getElementsByTagName("input");
if (cbk.checked == true) {
for (var i = 0; i < cbkson.length; i++) {
if (cbkson[i].type == "checkbox") {
cbkson[i].checked = true;
}
}
}
else {

for (var j = 0; j < cbkson.length; j++) {
if (cbkson[j].type == "checkbox") {
cbkson[j].checked = false;
}

}
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:Button ID="Addadds" runat="server" Text="添加图书" onclick="Addadds_Click" />
<asp:Panel ID="Panel1" runat="server" Visible="false">
图书类别:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Add"
runat="server" Text="添加" />
</asp:Panel>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
DataSourceID="ObjectDataSource1" onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="全选">
<HeaderTemplate >
<input id="cbkall" name="cbkallname" type="checkbox" onclick="SelectAll()">全选 
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" name="cbkson" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="编号"></asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="书名" SortExpression="Name" />
<%--<asp:TemplateField HeaderText="编辑">
<ItemTemplate>

</ItemTemplate>
</asp:TemplateField>--%>
<asp:CommandField ShowEditButton="True" />
</Columns>
</asp:GridView>
<asp:Button ID="Button1" runat="server" Text="删除所选项" />
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
SelectMethod="getAllGategroy" TypeName="BLL.CategroyMan" 
DataObjectTypeName="MODEL.gategroies" UpdateMethod="updateGategory1"></asp:ObjectDataSource>
</asp:Content>
后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace UI1.admin
{
public partial class CategoriesMan : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Addadds_Click(object sender, EventArgs e)
{
Panel1.Visible = !Panel1.Visible;
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[1].Text = (e.Row.RowIndex + 1).ToString();
}

}
}
}

点击更新后为什么传的值

不管点击那个Id都是0,nane的值是根据点击的行的图书名字但是id不是
mus的定义

请大神们给说说
c#asp.net myF