我现在在试着做一个简单的.net论坛,遇到这样一个问题,请各位帽子上戴着星星的兄弟们帮忙看看^o^
========================================================================================
功能:具体是这样的,比如我发了一张帖子,那下一回我进到这个帖子里,就会在标题后面多出一个小图标或者是“编辑”之类的字样,而别的用户就不会显示;同样我的回复也是如此。也就是能判断用户的身份然后给予对相应记录的编辑权限。条件:我现在是用的Session变量来存储用户标识号,准备根据这个来判断并动态生成。我的DataGrid里显示帖子用的是模板列,里边写了一个ImageButton问题:1.我要在什么事件里来编写代码?(ItemCreated?DataBinding?还是其它的什么?)
2.我如何能改变子控件ImageButton的属性,让它显示或不显示?请高手们指点,小生这厢有礼了!

解决方案 »

  1.   

    截取cuike519自定义控件的些代码
          public override void DataBind(){
                if (this.PagingMode == PagingMode.Cached) {
                this.ClearCache();
                this.GetAllData();
             }
             else {
                this.GetPageData();
             }         if(this.IsShowCheckAll && itest==1){
                itest++;
                TemplateColumn tcCheckBox = new TemplateColumn();
                //tcCheckBox.HeaderTemplate = new DataGridTemplate(ListItemType.Header,"选择");
                tcCheckBox.ItemTemplate = new DataGridTemplate(ListItemType.Item,"选择");
                this.Columns.AddAt(0,tcCheckBox);
             }         base.DataBind();
          }上面是帮定,下面是增加模板代码
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;namespace MY.Web.UI
    {
          public class DataGridTemplate : ITemplate {         ListItemType templateType;
             string columnName;         public DataGridTemplate(ListItemType type, string colname) {
                templateType = type;
                columnName = colname;
             }你可以在这个地方做写文章的,权限什么这类的
             public void InstantiateIn(System.Web.UI.Control container) {
                CheckBox chk = new CheckBox();
                switch(templateType) {
                   case ListItemType.Header:{
                      chk.ID = "chkAll";
                      chk.Text = "全选";
                      chk.Attributes["OnClick"] = "javascript:return SelectAll(this.checked,this.id)";
                      break;
                   }
                   case ListItemType.Item:{
                      chk.ID = "chkOne";
                      chk.Attributes.Add("onclick","javascript:return SelectAll(this.checked,this.id)");
                      break;
                   }
                   case ListItemType.AlternatingItem:{
                      chk.ID = "chkOne";
                      chk.Attributes.Add("onclick","javascript:return SelectAll(this.checked,this.id)");
                      break;
                   }
                   case ListItemType.EditItem:{
                      break;
                   }
                   case ListItemType.Footer:{
                      break;
                   }
                }            container.Controls.Add(chk);
             }   }
    }