日期:2014-05-17 浏览次数:21067 次
<%@ Page Language="C#" EnableViewState="true" AutoEventWireup="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> public System.Data.DataTable GetData() { System.Data.DataTable dataTable1 = new System.Data.DataTable("BlogUser"); dataTable1.Columns.Add(new System.Data.DataColumn("UserId", typeof(System.Int32))); dataTable1.Columns.Add(new System.Data.DataColumn("Title", typeof(System.String))); for (int i = 0; i < 8; i++) { dataTable1.Rows.Add(i, "测试" + i.ToString()); } return dataTable1; } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GridViewBind(); } } protected void GridViewCar_RowDataBound(object sender, GridViewRowEventArgs e) { } // 待命 protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { //currentRow.Cells[3].Text = SateToPicPerson(p.State); //得到所选中的 foreach (GridViewRow row in GridViewCar.Rows) { CheckBox chkSelect = row.FindControl("chkSelect") as CheckBox; if (chkSelect.Checked) { Response.Write("<li>选中的 userId = " + GridViewCar.DataKeys[row.RowIndex].Value.ToString()); } } GridViewBind(); } // 下岗 protected void ImageButton2_Click(object sender, ImageClickEventArgs e) { //得到所选中的 foreach (GridViewRow row in GridViewCar.Rows) { CheckBox chkSelect = row.FindControl("chkSelect") as CheckBox; if (chkSelect.Checked) { Response.Write("<li>选中的 userId = " + GridViewCar.DataKeys[row.RowIndex].Value.ToString()); } } GridViewBind(); } protected void GridViewBind() { GridViewCar.DataSource = GetData(); GridViewCar.DataBind(); } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:GridView ID="GridViewCar" runat="server" AutoGenerateColumns="False" Width="100%" DataKeyNames="UserId" CssClass="bind_vichle" BackColor="White" Font-Size="0.8em" OnRowDataBound="GridViewCar_RowDataBound"> <HeaderStyle HorizontalAlign="Center" Height="15px" BackColor="#2FA2E5" /> <RowStyle HorizontalAlign="Center" Height="14px" /> <Columns> <asp:TemplateField> <ItemTemplate> <asp:CheckBox ID="chkSelect" runat="server" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="UserId" HeaderText="编号"></asp:BoundField> <asp:BoundField DataField="Title" HeaderText="车牌号"></asp:BoundField> <asp:BoundField HeaderText="类型"></asp:BoundField> <asp:BoundField HeaderText="状态"></asp:BoundField> </Columns> </asp:GridView> <asp:ImageButton ID="ImageButton1" runat="server" ToolTip="待命" ImageUrl="