Peter Chan
asked on
Example of using Repeater
Hi,
I need one example, in which it is constructing a list of Linkbuttons using Repeater, by capturing the Student ID, name, class, from the student table, as the Text of the Linkbutton.
I need one example, in which it is constructing a list of Linkbuttons using Repeater, by capturing the Student ID, name, class, from the student table, as the Text of the Linkbutton.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many thanks all.
Carl,
For the list similar to this below
Carl,
For the list similar to this below
List<BankAccount> accounts = new List<BankAccount>()
{
new BankAccount { AccountNumber = "1234567890", AccountHolder = "Bob Smith", Balance = 100000.00M },
new BankAccount { AccountNumber = "0001234567", AccountHolder = "Sally Jones", Balance = -100.34M },
new BankAccount { AccountNumber = "1230001234", AccountHolder = "Jeremy Johnson", Balance = 800.34M },
new BankAccount { AccountNumber = "0001003456", AccountHolder = "Bruce Guinness", Balance = -80.15M },
new BankAccount { AccountNumber = "2000012789", AccountHolder = "Delia Thomson", Balance = 1200.00M }
};
I expect that the relevant columns are retrieved from a table upon that the page is being refreshed. how?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many thanks.
Can I have anything like Textbox or Label, within Repeater below, then I can further refresh it with the records retrieved from the table?
Can I have anything like Textbox or Label, within Repeater below, then I can further refresh it with the records retrieved from the table?
<asp:Repeater ID="AccountRepeater" runat="server">
<HeaderTemplate>
<div class="headerFooter">Active Accounts</div>
</HeaderTemplate>
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
<FooterTemplate>
<div class="headerFooter">This is the footer;</div>
</FooterTemplate>
</asp:Repeater>
Yes, you can use any control you like in the repeater sections. Just remember that the HeaderTemplate and FooterTemplate sections will only appear once for the whole repeater, rather than once per row of data.
ASKER
Thanks a lot.
If I want to have Linkbuttons inside the Repeater, how to update Text of Linkbutton inside the repeater, to the column values of the reader?
If I want to have Linkbuttons inside the Repeater, how to update Text of Linkbutton inside the repeater, to the column values of the reader?
You can use the Eval() syntax with the properties of any controls:
<asp:LinkButton ID="Link1" runat="server" Text='<%# Eval("YourField") %>' />
Note the use of apostrophes for the Text attribute.
ASKER
Thanks a lot.
Here is the repeater
t549.png
Here is the repeater
<asp:Repeater ID="Repeater" runat="server">
<HeaderTemplate>
<asp:LinkButton ID="Link1" runat="server" Text='<%# Eval("row1") %>' />
</HeaderTemplate>
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
<FooterTemplate>
<div class="headerFooter">This is the footer;</div>
</FooterTemplate>
</asp:Repeater>
Here are the codes that are executed upon that one button is clicked. SqlConnection conn = new SqlConnection(ConfigurationMancnt1r.ConnectionStrings["Mssqlconn2"].ConnectionString);
SqlCommand cmd;
SqlDataReader reader;
conn.Open();
try
{
cmd = new SqlCommand("SELECT top 5 ite_abbr+' '+ite_name+' '+ltrim(rtrim(cast(cnt1 as varchar)))+' '+pla1+' '+pla2 row1 FROM dbo.ite_tab order by 1", conn);
reader = cmd.ExecuteReader();
Repeater.DataSource = reader;
Repeater.DataBind();
}
catch (Exception ex)
{
lb_msg.Text = ex.Messcnt1 + ex.Source;
}
finally
{
conn.Close();
}
But I only get the repeater shown in Fig 1t549.png
That's because you aren't currently using the ItemTemplate section. The ItemTemplate is the section that display something per row. What you currently have as the HeaderTemplate should be the ItemTemplate.
If you look back at the article, the 3rd code sample in the "Defining the Repeater" section shows the ItemTemplate and AlternatingItemTemplate sections in use.
If you look back at the article, the 3rd code sample in the "Defining the Repeater" section shows the ItemTemplate and AlternatingItemTemplate sections in use.
ASKER
Many thanks. Upon that the relevant Linkbutton row within ItemTemplate is being clicked, how can we know the current Text of the Linkbutton row?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry, how do you put the reference to LinkButton_Click within Repeater, in the Markup page?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if Windows forms, check "The DataRepeater control" from http://emoreau.com/Entries/Articles/2008/03/Microsoft-Visual-Basic-Power-Packs-30.aspx