for( int i = 0; i < ListDataGrid.Items.Count; i++ )
{
CheckBox chk = ( CheckBox )ListDataGrid.Items[i].FindControl("CheckID");
StringBuilder CheckedID = new StringBuilder();
if( chk.Checked )
{
 ListDataGrid.Items[i].Cells[0].ToString();
}

解决方案 »

  1.   

    to  liudodo(天生我才必有用)
      StringBuilder 还需要引用什么吗? 提示我缺少using   语句....
        
      StringBuilder CheckedID = new StringBuilder();
      这句起什么作用?
      

  2.   

    使用StringBuilder 对象必须
    using System.Text;
      

  3.   

    to liudodo(天生我才必有用) 
    比如:datagrid中每页显示10行,运行时1,5,10总共3行被选中,要得到
       datagrid中1,5,10行的第一列的值
    if( chk.Checked )
    {
       ListDataGrid.Items[i].Cells[0].ToString();
    }得到的值是:System.Web.UI.WebControls.TableCellif( chk.Checked )
    {
       ListDataGrid.Items[i].Cells[0].Controls[2]ToString();
    }
    得到的值是:System.Web.UI.LiteralControl如何取得选中行,某一列的值...
      

  4.   

    正好现在的项目用了,发个例子:
     Public Sub DG_Checked(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Dim i, j As Integer
    dim IDstring as string
            For i = 0 To ds.Tables(0).Rows.Count - 1
                If CType(DG_Photo.Items(i).FindControl("DG_CheckBox"), CheckBox).Checked = True Then
                 IDstring =IDstring + DG_Photo.Items(i).Cells(0)
                 End If
            Next
      End Sub
      

  5.   

    提供一个解决的好办法:
    http://www.codeproject.com/aspnet/DataGridCheckBox.asp
    建议你看一看,这是一个能解决比你提的问题更多的东东。
    当然,首先,无疑,前面的大虾的回答是不错的(虽然我没验证其正确性)
      

  6.   

    aspx:<%@ Page language="c#" Codebehind="WebForm4.aspx.cs" AutoEventWireup="false" Inherits="test_datalist.WebForm4" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm4</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="WebForm4" method="post" runat="server">
    <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 72px" runat="server" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4" AutoGenerateColumns="False" PageSize="5" AllowPaging="True" Height="168px" Font-Size="10pt" Width="672px" DataKeyField="jh">
    <SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
    <ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
    <HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
    <FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
    <Columns>
    <asp:TemplateColumn>
    <HeaderStyle Width="1200px"></HeaderStyle>
    <HeaderTemplate>
    <FONT face="宋体"></FONT>
    </HeaderTemplate>
    <ItemTemplate>
    <FONT face="宋体">
    <asp:CheckBox id="CheckBox1" runat="server" Text="选择"></asp:CheckBox></FONT>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn DataField="model" HeaderText="机型">
    <HeaderStyle Width="1200px"></HeaderStyle>
    </asp:BoundColumn>
    <asp:BoundColumn DataField="jh" HeaderText="机号">
    <HeaderStyle Width="1200px"></HeaderStyle>
    </asp:BoundColumn>
    <asp:BoundColumn DataField="kxdate1" HeaderText="开箱日期">
    <HeaderStyle Width="1200px"></HeaderStyle>
    </asp:BoundColumn>
    <asp:BoundColumn DataField="xldate" HeaderText="修理日期" DataFormatString="{0:d}">
    <HeaderStyle Width="1200px"></HeaderStyle>
    </asp:BoundColumn>
    </Columns>
    <PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"></PagerStyle>
    </asp:DataGrid>
    <asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 256px; POSITION: absolute; TOP: 296px" runat="server" Text="Button"></asp:Button>
    <asp:LinkButton id="LinkButton1" style="Z-INDEX: 103; LEFT: 368px; POSITION: absolute; TOP: 304px" runat="server">LinkButton</asp:LinkButton>
    </form>
    </body>
    </HTML>
    cs:
    string nrirong="";
    for( int i = 0; i < this.DataGrid1.Items.Count; i++ )
    {
    CheckBox chk = ( CheckBox )this.DataGrid1.Items[i].FindControl("CheckBox1");
    StringBuilder CheckBox1 = new StringBuilder();
    if( chk.Checked )
    {
    nrirong =nrirong + this.DataGrid1.Items[i].Cells[0].ToString();
    }
    }
      

  7.   

    nrirong =nrirong + DataGrid1.Items[i].Cells[1].Text;