ASPX部份代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ztsort.aspx.cs" Inherits="Manager_ztsort" Title="Untitled Page" %><asp:Panel ID="plFriendLink" runat="server" Width="100%">
        <table align="center" cellpadding="1" cellspacing="0" width="95%">
            <tr>
                <th valign="middle" width="100%">
            <asp:GridView ID="gvFriendLink" runat="server" AutoGenerateColumns="False" CellPadding="5"
                CssClass="tableBorder" GridLines="None" Width="95%" OnRowEditing="gvFriendLink_RowEditing" OnRowDataBound="gvFriendLink_RowDataBound" OnRowDeleting="gvFriendLink_RowDeleting" DataKeyNames="id"  OnPageIndexChanging="gvFriendLink_PageIndexChanging" OnSelectedIndexChanged="gvFriendLink_SelectedIndexChanged">
                <Columns>
                    <asp:BoundField DataField="id" DataFormatString="{0}" HeaderText="Id" />
                    <asp:BoundField DataField="zt_cname" DataFormatString="{0}" HeaderText="专题标题" />
                    <asp:BoundField DataField="zt_type" DataFormatString="{0}" HeaderText="类别" />
                    <asp:ImageField DataImageUrlField="zt_pic" HeaderText="图片">
                        <ControlStyle BorderWidth="0px" Height="31px" Width="88px" />
                    </asp:ImageField>
                    <asp:BoundField DataField="homeshow" DataFormatString="{0}" HeaderText="首页输出" />
                    <asp:BoundField DataField="zt_px" DataFormatString="{0}" HeaderText="排序" />
                    <asp:CommandField HeaderText="操作" ShowCancelButton="False" ShowDeleteButton="True" ShowEditButton="True" />
                    <asp:TemplateField>
                                <ItemTemplate>
                                    &nbsp;<asp:CheckBox ID="CheckBox1" runat="server" />
                                </ItemTemplate>
                            </asp:TemplateField>
                </Columns>
            </asp:GridView>
            </th>
            </tr>
            <tr>
                <tH style="vertical-align: middle; height: 42px; text-align: center" colspan="2">
                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="设置管理员" Width="81px" />
                    &nbsp; &nbsp;&nbsp;
                    <asp:Button ID="Button2" runat="server" Text="删除用户" Width="75px" OnClick="Button2_Click" />
                    &nbsp; &nbsp;&nbsp;<asp:Button ID="Button3" runat="server" OnClick="Button3_Click"
                        Text="取消管理员" Width="83px" /></tH>
            </tr>
        </table>
            
        </asp:Panel>
以下为SC部份代码:
//设置管理员
    //protected void Button1_Click(object sender, GridViewDeleteEventArgs e)
    protected void Button1_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < gvFriendLink.Rows.Count; i++)
        {
            
            CheckBox cb = (CheckBox)gvFriendLink.Rows[i].FindControl("CheckBox1");  //在当前搜寻当前控件
            if (cb.Checked)
            {
                int id = int.Parse(gvFriendLink.DataKeys[i].Value.ToString());       //获取一个控件值
                //string sqlstr = "update glcity_cote_small set userType=1 where userID=" + id + "";
                //Class1.ExecSql(sqlstr);
                Response.Write(WebFunction.alertChk("请选88择要上传" + id + "的图片文件", 0));
                return;
                
                WebFunction.ExecuteSql("update glcity_cote_small set zt_state=2 where id=" + id );            }        }
        Response.Redirect("ztsort.aspx");
    }当我点击“设置管理员”按钮时,Button1_Click内的确有做循还操作,但CheckBox1总是没有被选中,我是打了勾的!!错在那呀?请求各位朋友帮忙!先谢了!!!

解决方案 »

  1.   

    给他一个属性吧。看看我发布的贴子~~~~gridview和Datagrid是不一样的
      

  2.   

    请问在哪给CheckBox加postback属性设为true?
    是不是象下面这样加?
    <asp:TemplateField>
                                    <ItemTemplate>
                                        &nbsp;<asp:CheckBox ID="CheckBox1" runat="server" postback="true" />
                                    </ItemTemplate>
                                </asp:TemplateField>象以上那样加了也是没有被子选中呀!!
      

  3.   

    他用的是gridview不是datagrid,这样加也没用的。
    你还是去看看我的贴子吧。
      

  4.   

    (CheckBox)gvFriendLink.Rows[i].cells[xxx].FindControl("CheckBox1");
    试一下?
      

  5.   

       
    fuda_1985朋友好!
    请问你的是哪个贴子呀?
    我就去看,急呀!
      

  6.   

    CS0117: “System.Web.UI.WebControls.GridViewRow”并不包含“cells”的定义(CheckBox)gvFriendLink.Rows[i].cells[xxx].FindControl("CheckBox1"); 
    把cells[xxx]中的XXX分别改成6、7、8、9、10都是出现以上错误信息!
      

  7.   

    CheckBox的postback属性设为true在aspx页面中点击CheckBox,对应的属性列表上面有AutoPostBack属性的,你设置为true啊