Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I bind data repeater but data not show:-
XML
<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>

C#
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.");
       }
   }
Posted
Updated 26-Aug-15 3:31am
v3
Comments
Schatak 26-Aug-15 9:32am    
What is the error? are you able to get data into AwardList from your database?

1 solution

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

C#
[Serializable]
    public class Award
    {
        public string Awardname { get; set; }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900