强类型转换不行吗,是想得到grid行中,格子里控件吗?,
例如:
foreach(DataGridItem myitem in DataGrid1.items)
{
CheckBox checkBox=(CheckBox)myItem.FindControl("CheckBox1");
然后就可以对 checkBox进行操作了
}

解决方案 »

  1.   

    foreach(DataGridItem myitem in DataGrid1.items) 

    CheckBox checkBox=(CheckBox)myItem.FindControl("CheckBox1"); 
    然后就可以对 checkBox进行操作了 
    }myItem.FindControl("CheckBox1")没有这个方法,这个是GRIDBIEW上的,
    ComponentArt.Web.UI.Grid中不是这样的
      

  2.   



    提醒下:
          我的是ComponentArt.Web.UI.Grid不是GRIDVIEW
         

      

  3.   

    1.为列设置放置可以触发事件的控件的服务器端模板   <ComponentArt:GridColumn ... DataCellServerTemplateId="linkButtonTemplate" /> 定义你要用的模板:   <ServerTemplates>    ...    <ComponentArt:GridServerTemplate ID="linkButtonTemplate" />      <Template>        <asp:LinkButton ID="lb" runat="server"          Text="ItemCommand" CommandName="MyCommand" />      </Template>    </ComponentArt:GridServerTemplate>  </ServerTemplates> 添加事件委托到后置代码  private void InitializeComponent()  {    ...     Grid1.ItemCommand += new Grid.ItemCommandEventHandler(Grid1_ItemCommand);  } 定义事件处理程序:   public void Grid1_ItemCommand(object sender, GridItemCommandEventArgs args)  {    Response.Write("Command " + ((LinkButton)args.Control).CommandName +       " issued on item " + args.Item["ID"]);  }
      

  4.   

    没用过ComponentArt.Web.UI.Grid!!
      

  5.   

    还是用findcontrol方法转换成控件对象后再进行处理
      

  6.   

    一般查找控件都是采用findControl方法的。试看看。关键在于ID要确定。搜索范围要尽量精确位置
      

  7.   

    findControl(1,2,3,4)
    4个参数
    1,是层
    2,是列的索引
    3,是行的索引
    4,是控件的ID
    我的参数都传了就是找不到控件,一直是NULL,没遮啊,具体该怎样去找??
    我的方法是:
      

  8.   


    1,先创建了一个服务端模板(并且在次加载了用户控件(TEXTBOX)):
     private void InitServerTemplate()
            {
                var serverTemplates = new List<GridServerTemplate>
                {
                    new GridServerTemplate { ID = "text", Template = Page.LoadTemplate("~/useControl/Text.ascx") },
                    
                };
                foreach (GridServerTemplate template in serverTemplates)
                {
                    SimpleGrid1.Grid.ServerTemplates.Add(template);
                }
            }2,初始化的时候定义了这个服务端控件;
     private void InitGrid()
            {
                var cols = new List<GridColumn>
                {
                ...
                    new GridColumn {HeadingText = "单价(元/m2)", DataField = "TotalItemUnitPrice", Align = ComponentArt.Web.UI.TextAlign.Left, DataCellServerTemplateId="text"},
                                ...
                   
                };
                foreach (GridColumn col in cols) { SimpleGrid1.Grid.Levels[0].Columns.Add(col); }
            }3,我是在事件里对那个用户控件赋值并取ID名的:
      protected void SimpleGrid1_OnItemContentCreated(object sender,GridItemContentCreatedEventArgs e)
            {
                object[] info = e.Item.ToArray();
                switch (e.Column.DataCellServerTemplateId)
                {
                    case "text":
                        {
                            e.Content.Controls[0].ID = "ids";
                            Text txt = (e.Content.Controls[0] as Text);
                            txt.ID = "txt";
                            txt.Value = info[4].ToString();
                        } break;
                }
            }
    4,最后在一个自定义的非事件的方法里准备获取此用户控件
    private void save(string strID)
            {
                for (int i = 0; i < SimpleGrid1.Grid.Items.Count; i++)
                {
                     object[] item = SimpleGrid1.Grid.Items[i].ToArray();
                     Grid.findControl(0,i,4,"txt");
                  //...
                }
            }
    我用过Grid.findControl(1,2,3,4)
    参数是这样传的:
    Grid.findControl(0,i,4,"txt");
    可获取到的却是NULL
      

  9.   

    没用过ComponentArt.Web.UI.Grid!!帮你顶了。