本帖最后由 七色北斗星 于 2012-8-1 08:13 编辑
强列建议将3.1.8的Grid,TemplateField修改回3.1.3版本的源码
因为我系统内的角色权限配置用的是Grid,TemplateField,CheckBoxList控件,
3.1.3的后台取值是通过Request.Form.AllKeys获取的,CheckBoxList内的每一个单个控件都会生成一个key("Grid1_0$cbList$0","Grid1_0$cbList$1","Grid1_0$cbList$2","Grid1_1$cbList$0","Grid1_1$cbList$1","Grid1_1$cbList$2"),这样可以取出2行3列的值。
3.1.8的通过Request.Form.AllKeys获取的值是("Panel1$Grid1$c1r7$cbList$0","Panel1$Grid1$c1r7$cbList$1"),只能取出两列,里面的子项是无法获取到的。
以下是两个版本的参照对比,从3.1.4一直到3.1.8都是不能用的,或许是我没找到新版的取值方法,如果有谁能取到新版的值请不吝赐教。
3.1.3版的
- internal override string GetColumnValue(GridRow row)
- {
- string result = String.Empty;
- if (_itemTemplate != null)
- {
- StringBuilder output = new StringBuilder();
- using (StringWriter sw = new StringWriter(output, CultureInfo.CurrentCulture))
- {
- using (HtmlTextWriter htw = new HtmlTextWriter(sw))
- {
- using (GridRowControl control = new GridRowControl(row.DataItem, row.RowIndex))
- {
- _itemTemplate.InstantiateIn(control);
- control.ID = String.Format("{0}_{1}", Grid.ID, row.RowIndex);
- control.DataBind();
- control.RenderControl(htw);
- }
- }
- }
- result = output.ToString();
- }
- return result;
- }
复制代码
3.1.8版的
- internal override string GetColumnValue(GridRow row)
- {
- GridRowControl control = row.TemplateContainers[ColumnIndex];
- return String.Format("#@TPL@#{0}", control.ClientID);
- //return String.Format("<div id="{0}_container"></div>", control.ClientID);
- //string result = String.Empty; //if (_itemTemplate != null)
- //{
- // StringBuilder output = new StringBuilder();
- // using (StringWriter sw = new StringWriter(output, CultureInfo.CurrentCulture))
- // {
- // using (HtmlTextWriter htw = new HtmlTextWriter(sw))
- // {
- // //using (GridRowControl control = new GridRowControl(row.DataItem, row.RowIndex))
- // //{
- // // _itemTemplate.InstantiateIn(control);
- // // control.ID = String.Format("{0}_{1}", Grid.ID, row.RowIndex);
- // // control.DataBind(); // // control.RenderControl(htw); // //}
- // //GridRowControl control = row.TemplateContainers[ColumnIndex];
- // //if (control != null)
- // //{
- // // control.DataBind();
- // // //control.RenderControl(htw);
- // //}
- // }
- // } // result = output.ToString();
- //} //return result;
- }
复制代码 我尝试过用FindControl取值,但无论选中的项是选中还是未选中,都会False,最终只能用上面的Request.Form.AllKeys来获取。
System.Web.UI.WebControls.CheckBoxList cbList = (System.Web.UI.WebControls.CheckBoxList)Grid1.Rows[0].FindControl("cbList");
|