前台代码:
<%@ 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的定义
请大神们给说说
在GridView列表属性的 DataKeyNames 项里添加所设为主键的字段名就可以
果然是大神 哈哈 原来一直不知道DataKeyNames什么用,现在终于明白了,哈哈谢谢啦
Id都没绑定当然没值
你的断点打在哪儿啊,mus是哪儿来的东东?