http://sz.luohuedu.net/xml/ShowDetail.asp?id=FF130C7F-3650-4DA6-8943-8AA4AF3E3459

解决方案 »

  1.   

    我要不要在模板里加入AutoPostBack=True EnableViewState=True?
      

  2.   

    look into 
    http://www.metabuilders.com/Tools/RowSelectorColumn.aspxand DataGrid Girl's explanations:http://www.datagridgirl.com/rowselector.aspxotherwise, you can do<asp:CheckBox id="chkSelectAll" runat="server" AutoPostBack="true"
    OnCheckedChanged="Check_Clicked"
    ></asp:CheckBox>
    void Check_Clicked(Object sender, EventArgs e) 
    {
        bool b = ((CheckBox)sender).Checked;
        foreach (DataGridItem dgi in YourDataGrid1.Items)
        {
              CheckBox cb = (CheckBox)dgi.FindControl("chkDelete");
              cb.Checked = b;
        }        
    }or you can always do it on the client side with javascript
      

  3.   

    <asp:TemplateColumn HeaderText="XXXXXX">
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
    <ItemTemplate>
    <asp:CheckBox id=CheckBox1 runat="server" checked='<%# DataBinder.Eval(Container.DataItem, "XXXXXX") %>'>
    </asp:CheckBox>
    </ItemTemplate>
    </asp:TemplateColumn>
    然后在CheckedChanged事件获得:
    (CheckBox)e.Item.FindControl("XXXXXX")
      

  4.   

    string test = "(";
    foreach (DataGridItem CheckBoxItem in this.UserList.Items)
    {
    if (((HtmlInputCheckBox)CheckBoxItem.FindControl("chkSelection")).Checked)
    {
    ((HtmlInputCheckBox)CheckBoxItem.FindControl("chkSelection")).Checked = false;
    test +=((HtmlInputCheckBox)CheckBoxItem.FindControl("chkSelection")).Value+",";
    }
    }
    test += "0)";
    con.opensql();
    string sql ="delete from admin where id in"+test;
    SqlCommand command1=new SqlCommand(sql,con.conn);
    command1.ExecuteNonQuery();
    con.closesql();
      

  5.   

    protected System.Web.UI.WebControls.DataGrid UserList;
    protected System.Web.UI.HtmlControls.HtmlInputCheckBox chkSelection;
    string test = "(";
    foreach (DataGridItem CheckBoxItem in this.UserList.Items)
    {
    if (((HtmlInputCheckBox)CheckBoxItem.FindControl("chkSelection")).Checked)
    {
    ((HtmlInputCheckBox)CheckBoxItem.FindControl("chkSelection")).Checked = false;
    test +=((HtmlInputCheckBox)CheckBoxItem.FindControl("chkSelection")).Value+",";
    }
    }
    test += "0)";
    con.opensql();
    string sql ="delete from admin where id in"+test;
    SqlCommand command1=new SqlCommand(sql,con.conn);
    command1.ExecuteNonQuery();
    con.closesql();
      

  6.   

    Function checkitem() As ArrayList
            Dim ditem As DataGridItem
            Dim rdo As CheckBox
          
           
            For Each ditem In DataGrid1.Items
                rdo = ditem.FindControl("rd1")
                If rdo.Checked = True Then               
                    checkitem.add(ditem.ItemIndex)
                End If
            Next
            
        End Function然后把CHECKITEM中的值取出来就可以了
      

  7.   

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim sqlstr As String
            Dim rscmd As OleDbCommand
            Dim rolecodes As ArrayList
            Dim rolecode
            Dim ischecked As Integer
            ischecked = 0
            Dim item As DataGridItem
            Dim ch As CheckBox
            Dim i As Integer
            rolecodes = New ArrayList
            For Each item In DataGrid1.Items
                ch = item.FindControl("chck")
                If ch.Checked = True Then
                    ischecked = 1
                    rolecodes.Add(DataGrid1.DataKeys(item.ItemIndex))
                End If
            Next
            If ischecked = 1 Then
                For i = 0 To rolecodes.Count - 1
                    rolecode = rolecodes(i)
                    sqlstr = "delete from roles where code='" & rolecode & "'"
                    rscmd = New OleDbCommand(sqlstr, conn)
                    rscmd.ExecuteNonQuery()            Next
                datagrid1bind()
            End If
        End Sub
      

  8.   

    我是用隐藏代码写的,如何获得列头标题上的CheckBox事件啊?
      

  9.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=FF130C7F-3650-4DA6-8943-8AA4AF3E3459
      

  10.   

    <asp:TemplateColumn>
    <HeaderTemplate>
    <asp:CheckBox id="chkSelectAll" runat="server" AutoPostBack="True" OnCheckedChanged="check1"></asp:CheckBox>
    </HeaderTemplate>
    .......................
     Public Sub check1(ByVal s As Object, ByVal e As EventArgs)
            Dim item As DataGridItem
            Dim ch As CheckBox        For Each item In DataGrid1.Items
                ch = item.FindControl("chkDelete")
                If ch.Checked = False Then
                    ch.Checked = True
                End If
            Next    End Sub
      

  11.   

    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if((e.Item.ItemType == ListItemType.Header))
    {
    LinkButton lbAdd=new LinkButton();
    lbAdd=e.Item.FindControl("btnAdd") as LinkButton ;
    lbAdd.Attributes.Add("onclick","javascript:return confirm('真的要添加记录吗?')");
    }修改一下就可以
    }
      

  12.   

    在隐藏代码的情况下CheckedChanged事件如何写?给个例子好吗?是写在隐藏类呢,还是在aspx脚本写?
      

  13.   

    看看这个控件我已经将你说的这个方法封装到DataGrid里面了!看看例子!js的!在选择的时候不用和服务器交互。
    至于怎么得到哪一行选中我想可以使用遍历的方法在服务器上实现!
      

  14.   

    <Columns>
    前台
    <asp:TemplateColumn>
    <ItemTemplate><INPUT  id="Checkbox1" value="<%#DataBinder.Eval(Container.DataItem,"LOC_LOC")%>" type="checkbox" name="Checkbox1" >
    </ItemTemplate>
    </asp:TemplateColumn> </Columns>
    后台:
    string []arrayCheckbox = this.Request["Checkbox1"].Trim().Split(',');   
      

  15.   

    在页面上:
    <Columns>
    <asp:TemplateColumn HeaderText="全选">
    <HeaderTemplate>
    <asp:CheckBox id="chkSelectAll" runat="server" Height="5px" OnCheckedChanged="chkSelectAll_Click"
    Runat="server" EnableViewState="True"></asp:CheckBox>
    </HeaderTemplate>
    <HeaderStyle Width="20px" Wrap="False" Height="7px"></HeaderStyle>
    <ItemTemplate>
    <asp:CheckBox id="chkDelete" runat="server" Height="5px" Runat="server" EnableViewState="True"></asp:CheckBox>
    </ItemTemplate>
    <ItemStyle Wrap="False" Height="7px"></ItemStyle>
    </asp:TemplateColumn>在隐藏类代码:
    Public Class department
        Inherits System.Web.UI.Page    Public Sub chkSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Dim item As DataGridItem
            Dim selection As CheckBox
            For Each item In dgdDepartment.Items
                selection = CType(item.FindControl("chkDelete"), CheckBox)
                selection.Checked = True
                'If Not selection Is Nothing Then
                '    selection.Checked = True
                'End If
            Next
        End Sub
    End Class但发现无论如何点击标题行的chkSelectAll,都不执行Sub chkCheckAll_Click过程
    请教各位是不是在哪里写错了,代码没有错,但就是没有执行。
      

  16.   

    我用的是radiobutton 和楼主同样的问题也没解决
    关注
      

  17.   

    你按我的方法写不行吗?我是测试过可以的啊!
    <asp:CheckBox id="chkSelectAll" runat="server" Height="5px" OnCheckedChanged="chkSelectAll_Click"
    Runat="server" AutoPostBack="True" >
    注意加上AutoPostBack="True"
    ...........................
    Public Sub chkSelectAll_Click(s As System.Object,  e As EventArgs)selection = item.FindControl("chkDelete")
                selection.Checked = True..............
    改成这样是绝对可以的!
      

  18.   

    对,加上AutoPostBack="True"就可以了,谢谢。
      

  19.   

    补充一个问题,为什么我标题列的那个CheckBox只要一选中,总是选中,即使在点击,PostBack还是选中状态。