gridview中我创建了CheckBoxField ,但不可选,请问怎样设置才能在页面修改这个CheckBoxField 做个模板列```列里放个CheckBox就行了``` 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果我只想用CheckBoxField,不用模板列,能不能实现? <asp:View ID="Management_ZP" runat="server"> 招聘信息管理: <asp:Button ID="Btn_ZP" runat="server" Text="显示招聘" OnClick="Btn_ZP_Click" /><br /> <br /> <asp:GridView ID="Gv_Zp" runat="server" Width="759px" AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal" OnRowCommand="Gv_Zp_RowCommand"> <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" /> <Columns> <asp:BoundField DataField="ZpID" HeaderText="ID" SortExpression="ZpID" /> <asp:BoundField DataField="ZpTitle" HeaderText="职位名称" SortExpression="ZpTitle" /> <asp:BoundField DataField="ZpBody" HeaderText="具体要求" SortExpression="ZpBody" /> <asp:CheckBoxField DataField="IsShow" HeaderText="是否发布" SortExpression="IsShow" /> <asp:TemplateField HeaderText="删除"> <ItemTemplate> <asp:Button ID="Btn_Del_Zp" runat="server" CommandName="Del_Zp" Text="删除" CommandArgument='<%# Container.DataItemIndex %>' OnClientClick="return confirm('确定删除吗?')" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="编辑"> <ItemTemplate> <asp:Button ID="Btn_Edit_Zp" runat="server" CommandName="Edit_Zp" Text="编辑" CommandArgument='<%# Container.DataItemIndex %>' /> </ItemTemplate> </asp:TemplateField> </Columns> <EmptyDataTemplate> 没有信息! </EmptyDataTemplate> <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" /> <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" /> <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" /> <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" /> <AlternatingRowStyle BackColor="#F7F7F7" /> </asp:GridView> <asp:CheckBoxField DataField="IsShow" HeaderText="是否发布" SortExpression="IsShow" /> 不是用模版列哦~~ protected void Gv_Zp_RowCommand(object sender, GridViewCommandEventArgs e) { int iIndex = Convert.ToInt32(e.CommandArgument); GridViewRow gvr = Gv_Zp.Rows[iIndex]; if (e.CommandName == "Edit_Zp") { Tb_ZpID.Text = gvr.Cells[0].Text; Tb_ZpTitle.Text = gvr.Cells[1].Text; Tb_ZpBody.Text = gvr.Cells[2].Text; Cb_ZpISShow.Checked = ((CheckBox)gvr.Cells[3].Controls[0]).Checked; //true of false } } }然后把Cb_ZpISShow.Checked的内容重新更新入数据库 如果想直接在GridView更新的话:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %><!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 ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ZpID" DataSourceID="SqlDataSource1"> <Columns> <asp:CommandField ShowEditButton="True" /> <asp:BoundField DataField="ZpID" HeaderText="ZpID" InsertVisible="False" ReadOnly="True" SortExpression="ZpID" /> <asp:BoundField DataField="ZpTitle" HeaderText="ZpTitle" SortExpression="ZpTitle" /> <asp:BoundField DataField="ZpBody" HeaderText="ZpBody" SortExpression="ZpBody" /> <asp:CheckBoxField DataField="IsShow" HeaderText="IsShow" SortExpression="IsShow" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=no6;Initial Catalog=Ym;Integrated Security=True" DeleteCommand="DELETE FROM [Zp] WHERE [ZpID] = @ZpID" InsertCommand="INSERT INTO [Zp] ([ZpTitle], [ZpBody], [IsShow]) VALUES (@ZpTitle, @ZpBody, @IsShow)" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [Zp]" UpdateCommand="UPDATE [Zp] SET [ZpTitle] = @ZpTitle, [ZpBody] = @ZpBody, [IsShow] = @IsShow WHERE [ZpID] = @ZpID"> <DeleteParameters> <asp:Parameter Name="ZpID" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="ZpTitle" Type="String" /> <asp:Parameter Name="ZpBody" Type="String" /> <asp:Parameter Name="IsShow" Type="Boolean" /> <asp:Parameter Name="ZpID" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="ZpTitle" Type="String" /> <asp:Parameter Name="ZpBody" Type="String" /> <asp:Parameter Name="IsShow" Type="Boolean" /> </InsertParameters> </asp:SqlDataSource> </div> </form></body></html> TreeView实现导航 gridview自定义 第一页 上一页 下一页 最后一页 ASP.net 真分页 有请高手“未将对象引用设置到对象的实例” asp.net2.0中数据控件、更新与参数 如何弥补DataView的局限性-100分 水晶报表打印问题 承接各类ASP.net(C#)软件开发[成都] DataReader怎样分页?怎么把DataGrid中的所有文字读出? 江雨等老手,看看treeview的问题吧 请问 override 与 new 的区别 ??? 走字程序
招聘信息管理:
<asp:Button ID="Btn_ZP" runat="server" Text="显示招聘" OnClick="Btn_ZP_Click" /><br />
<br />
<asp:GridView ID="Gv_Zp" runat="server" Width="759px" AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal" OnRowCommand="Gv_Zp_RowCommand">
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<Columns>
<asp:BoundField DataField="ZpID" HeaderText="ID" SortExpression="ZpID" />
<asp:BoundField DataField="ZpTitle" HeaderText="职位名称" SortExpression="ZpTitle" />
<asp:BoundField DataField="ZpBody" HeaderText="具体要求" SortExpression="ZpBody" />
<asp:CheckBoxField DataField="IsShow" HeaderText="是否发布" SortExpression="IsShow" />
<asp:TemplateField HeaderText="删除">
<ItemTemplate>
<asp:Button ID="Btn_Del_Zp" runat="server" CommandName="Del_Zp" Text="删除" CommandArgument='<%# Container.DataItemIndex %>' OnClientClick="return confirm('确定删除吗?')" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="编辑">
<ItemTemplate>
<asp:Button ID="Btn_Edit_Zp" runat="server" CommandName="Edit_Zp" Text="编辑" CommandArgument='<%# Container.DataItemIndex %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
没有信息!
</EmptyDataTemplate>
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#F7F7F7" />
</asp:GridView>
不是用模版列哦~~
{
int iIndex = Convert.ToInt32(e.CommandArgument);
GridViewRow gvr = Gv_Zp.Rows[iIndex]; if (e.CommandName == "Edit_Zp")
{ Tb_ZpID.Text = gvr.Cells[0].Text;
Tb_ZpTitle.Text = gvr.Cells[1].Text;
Tb_ZpBody.Text = gvr.Cells[2].Text;
Cb_ZpISShow.Checked = ((CheckBox)gvr.Cells[3].Controls[0]).Checked; //true of false }
}
}
然后把Cb_ZpISShow.Checked的内容重新更新入数据库
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ZpID"
DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="ZpID" HeaderText="ZpID" InsertVisible="False" ReadOnly="True"
SortExpression="ZpID" />
<asp:BoundField DataField="ZpTitle" HeaderText="ZpTitle" SortExpression="ZpTitle" />
<asp:BoundField DataField="ZpBody" HeaderText="ZpBody" SortExpression="ZpBody" />
<asp:CheckBoxField DataField="IsShow" HeaderText="IsShow" SortExpression="IsShow" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=no6;Initial Catalog=Ym;Integrated Security=True"
DeleteCommand="DELETE FROM [Zp] WHERE [ZpID] = @ZpID" InsertCommand="INSERT INTO [Zp] ([ZpTitle], [ZpBody], [IsShow]) VALUES (@ZpTitle, @ZpBody, @IsShow)"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [Zp]" UpdateCommand="UPDATE [Zp] SET [ZpTitle] = @ZpTitle, [ZpBody] = @ZpBody, [IsShow] = @IsShow WHERE [ZpID] = @ZpID">
<DeleteParameters>
<asp:Parameter Name="ZpID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="ZpTitle" Type="String" />
<asp:Parameter Name="ZpBody" Type="String" />
<asp:Parameter Name="IsShow" Type="Boolean" />
<asp:Parameter Name="ZpID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ZpTitle" Type="String" />
<asp:Parameter Name="ZpBody" Type="String" />
<asp:Parameter Name="IsShow" Type="Boolean" />
</InsertParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>