Anyway, I set the class inside the datarow repeater, finding the data id when it does the postback?

I want to set the class for the repeater when doPostBack for this dataID i wan but dun noe can / can not? Below code is only an example:

<body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server" EnablePageMethods="true" /> <asp:UpdatePanel ID="UpdatePanel2" runat="server" > <ContentTemplate> <asp:Repeater ID="Repeater1" runat="server" DataSourceID="dsInbox"> <ItemTemplate> <tr id="trInbox"> <td width="370px" height="25px"><div align="left" class="style95">&nbsp;<%# DisplaySubject(Eval("inbSubject").ToString(), Eval("inbMsg").ToString())%></div></td> <td width="80px" height="25px"><div align="left" class="style95">&nbsp;<%# Eval("inbCreatedAt","{0:MM-dd-yyyy}") %></div></td> <td width="94px" height="25px"><div align="left" class="style95">&nbsp;<%# Eval("DataId") %></div></td> </tr> </ItemTemplate> </asp:Repeater> </ContentTemplate> </asp:UpdatePanel> 

for c # code i can create class / style i wan

  protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { Repeater1.DataBind(); //find the data row ID and set class/style when loaded } } 
0
source share
1 answer

If you want to set a class for each row, and you need a data identifier, then your best approach is to process it, since each row is bound:

 <asp:Repeater ID="Repeater1" runat="server" DataSourceID="dsInbox" OnItemDataBound="Repeater1_ItemDataBound"> 

and in code:

 protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)) { MyType myItem = (MyType)e.Item.DataItem; var dataId = myItem.DataId; // Do whatever you need here. } } 
0
source

Source: https://habr.com/ru/post/1410955/


All Articles