繁体   English   中英

如何从AspxGridView绑定标签?

[英]How to bind labels from AspxGridView?

我使用了Dx AspxGridView,并尝试绑定该网格中的一些标签。

我在此网格中有一行,并且有12列。

我想像这样:

Label1.Tex =列1的值

Label2.Tex =列2的值

Label3.Tex =列3的值

  <dx:ASPxLabel runat="server" ID="Label1" Text=""></dx:ASPxLabel>

  <dx:ASPxLabel runat="server" ID="Label2" Text=""></dx:ASPxLabel>

  <dx:ASPxLabel runat="server" ID="Label3" Text=""></dx:ASPxLabel>
  .

  .  

  .

Label12.Tex =列12的值

我的代码:

     protected void ASPxGridView1_HtmlRowCreated(object sender, 
     ASPxGridViewTableRowEventArgs e)

     {
        if (e.RowType != DevExpress.Web.ASPxGridView.GridViewRowType.Data) return;

        DevExpress.Web.ASPxEditors.ASPxLabel label = 
        ASPxGridView1.FindRowCellTemplateControl(e.VisibleIndex, null, "Label1") as 
        DevExpress.Web.ASPxEditors.ASPxLabel;

  //for integer value of column
        int Value=(int) e.GetValue("Column1");
        label.Text = string.Format("{0}",Value);

    DevExpress.Web.ASPxEditors.ASPxLabel label2 = 
    ASPxGridView1.FindRowCellTemplateControl(e.VisibleIndex, null, "Label3") as 
    DevExpress.Web.ASPxEditors.ASPxLabel;

        int Value2=(int) e.GetValue("Column2");
        label2.Text = string.Format("{0}",Value2);

   DevExpress.Web.ASPxEditors.ASPxLabel label3 = 
   ASPxGridView1.FindRowCellTemplateControl(e.VisibleIndex, null, "Label3") as 
   DevExpress.Web.ASPxEditors.ASPxLabel;


  //for string value of column
   string Value3=(string) e.GetValue("Column3");
   label.3Text = string.Format("{0}",Value3);

  }

我得到这个错误

 System.NullReferenceException: Object reference not set to an instance of an object.

在线

 label.Text = string.Format("{0}",Value);

我解决了我的问题。

  protected void ASPxGridView1_CustomColumnDisplayText(object sender, 
   ASPxGridViewColumnDisplayTextEventArgs e)
    {
        if (e.Column.FieldName == "Column1")
        {
            Label1.Text = e.Value.ToString();
        }

        if (e.Column.FieldName == "Column2")
        {

            Label2.Text = e.Value.ToString();
        }

       . 

       .

       if (e.Column.FieldName == "Column12")
        {

            Label12.Text = e.Value.ToString();
        }

    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM