如何在中继器中绑定数据但数据未显示 [英] How Do I Bind Data In Repeater In But Data Not Show

查看:88
本文介绍了如何在中继器中绑定数据但数据未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我绑定数据转发器但数据未显示: -

I bind data repeater but data not show:-

<tr>
                      <td valign="top">
                          <asp:Label ID="lblAwards" runat="server" Text="AWARDS/ REWARDS/ DISTINCTIONS"></asp:Label>
                      </td>
                      <td class="fieldcell" style="width: 70%">
                          <asp:TextBox ID="txtAwards" runat="server" Width="90%" TextMode="MultiLine" Rows="2"></asp:TextBox>
                          <asp:ImageButton ID="imgbtnAddAwards" runat="server" Width="20px" Height="20px" ImageUrl="~/images/Icons/Add.png" OnClick="imgbtnAddAwards_Click" ToolTip="Add" />
                  </tr>
                  <tr>
                      <td colspan="2">
                          <asp:Repeater ID="repAwards" runat="server" Visible="true">
                              <ItemTemplate>
                                  <asp:Label ID="lblAwardName" runat="server" Text='<%#Eval("Awardname")+", " %>'></asp:Label>
                              </ItemTemplate>
                          </asp:Repeater>
                          <asp:ImageButton ID="imgbtnEditAward" runat="server" ImageUrl="~/images/Icons/Edit.png" Height="20px" Width="20px" ToolTip="Edit" Visible="false" OnClick="imgbtnEditAward_Click" />
                      </td>
                  </tr>




public class Award
   {
       public string Awardname { get; set; }
   }

protected void imgbtnAddAwards_Click(object sender, ImageClickEventArgs e)
   {
       if (txtAwards.Text.Trim() != "")
       {
           imgbtnEditAward.Visible = true;
           List<Award> Awardlist;
           if (ViewState["Award"]!= null)
               Awardlist = (List<Award>)ViewState["Award"];
           else
               Awardlist = new List<Award>();
           Awardlist.Add(new Award() { Awardname = txtAwards.Text.Trim() });
           ViewState["Award"] = Awardlist;
           //List<Award> Awardlist = (List<Award>)ViewState[
"Award"];
           repAwards.DataSource = Awardlist;
           repAwards.DataBind();
       }
       else
       {
           ShowMessage("Please enter Awards first.");
       }
   }

推荐答案

我能够通过制作奖励来获取您的代码并使其成功class serializable:



I was able to take your code and make it work simply by making the Award class serializable:

[Serializable]
    public class Award
    {
        public string Awardname { get; set; }
    }


这篇关于如何在中继器中绑定数据但数据未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆