asp.net - Is there a cleaner / more efficient way of splitting strings for use in a gridview? -
i have entity gets bound gridview , has string value this: 'data1|data2|data3|data4'.
is there more efficient or better way of doing method using below?
<asp:repeater runat="server" id="rptcentres"> <itemtemplate> <h2><%#eval("centre.name") %> ( <%#eval("entities.count") %> )</h2> <asp:gridview runat="server" id="dgshotlist" autogeneratecolumns="false"> <columns> <asp:templatefield> <itemtemplate> <p><%#eval("imagecontainer.title").tostring().split('|')[0]%></p> </itemtemplate> </asp:templatefield> <asp:templatefield> <itemtemplate> <p><%#eval("imagecontainer.title").tostring().split('|')[1]%></p> </itemtemplate> </asp:templatefield> <asp:templatefield> <itemtemplate> <p><%#eval("imagecontainer.title").tostring().split('|')[2]%></p> </itemtemplate> </asp:templatefield> <asp:templatefield> <itemtemplate> <p><%#eval("imagecontainer.title").tostring().split('|')[3]%></p> </itemtemplate> </asp:templatefield> </columns> </asp:gridview> </itemtemplate> </asp:repeater>
assuming, explicitly bind data repeater only:
<asp:repeater runat="server" id="rptcentres"> <itemtemplate> <h2><%# eval("centre.name") %>(<%# eval("entities.count") %>)</h2> <asp:gridview runat="server" id="dgshotlist" autogeneratecolumns="false" datasource=<%# ((string)eval("imagecontainer.title")).split('|') %>> <columns> <asp:templatefield> <itemtemplate> <p><%# container.dataitem %></p> </itemtemplate> </asp:templatefield> </columns> </asp:gridview> </itemtemplate> </asp:repeater>
here specify data source inner gridview
title splitted |
symbol should of type string[]
by using ((string)eval("imagecontainer.title")).split('|')
.
Comments
Post a Comment