| |

VerySource

 Forgot password?
 Register
Search
View: 647|Reply: 4

When the Repeater is bound, how to get the first line?

[Copy link]

2

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Invalid IP Address

Post time: 2020-1-5 13:40:01
| Show all posts |Read mode
Have a repeater
<asp: Repeater id = "ShareComments1" EnableViewState = "false" OnItemCommand = "Repeater_ItemCommand" OnItemDataBound = "Repeater_ItemDataBound" Runat = "server">

Display 5 rows of data in total

cs file

protected void Repeater_ItemDataBound (object sender, RepeaterItemEventArgs e)
     {
       DbDataRecord dr = (DbDataRecord) e.Item.DataItem;

 How to determine which line is the first line, then display an Image control
Image is not displayed in the next 4 lines.
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-1-5 16:39:01
| Show all posts
if (e.Item.ItemIndex == 0)
Reply

Use magic Report

2

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Invalid IP Address

 Author| Post time: 2020-1-5 18:00:01
| Show all posts
protected void Repeater_ItemDataBound (object sender, RepeaterItemEventArgs e)
     {
        if (e.Item.ItemIndex == 0)
         {
           HtmlImage Image1 = (HtmlImage) e.Item.FindControl ("pic");
           if (Image1! = null)
            Image1.Visible = true;
          }
     }

Or all the pictures are displayed, what's the problem?


 <asp: Repeater id = "Shops1" OnItemDataBound = "Repeater_ItemDataBound" runat = "server">
                      <ItemTemplate>
                        <div style = "border: 1px # D6D4D4 solid; padding: 3px"> <a href="/Shop/ShopDetail.aspx?ShopId=<%# Eval("Id")%> "> <img id =" pic "Visible =" false "width =" 150 "src =" <% # Eval ("Image")%> "> </a> </ div>
                        <a class="blues" href="/Shop/ShopDetail.aspx?ShopId=<%# Eval("Id")%> "> <% # Eval (" Name ")%> </a> <br>
                      </ ItemTemplate>
                     </ asp: Repeater>
Reply

Use magic Report

2

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Invalid IP Address

 Author| Post time: 2020-1-5 18:42:01
| Show all posts
If it is e.Item.FindControl ("pic");

pic is a div,

What type should it be converted to?
Reply

Use magic Report

0

Threads

21

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-1-6 12:27:01
| Show all posts
Try this
Put an asp: literal in itemtemplate
Then, if e.item.itemindex = 0 specifies the text attribute of this asp: literal as
<img src = '' />
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list