c# - Binding a List inside of a List to a GridView -


i have class different kinds of data members, including list of strings. when bind data gridview, want able separate out list of strings different columns in gridview. these strings more flags, there max of 3 flags. list empty, if no flags apply, or contain 1 or 2 flags. how can separate out these flags different gridview columns? need in onrowdatabound event?

current, aspx code looks this. want able change imageurl of image controls based on if flag raised or not.

<asp:templatefield headertext="tax" sortexpression="tax">     <itemtemplate>         <asp:image id="imgtax" runat="server" />     </itemtemplate> </asp:templatefield>      <asp:templatefield headertext="compliance" sortexpression="compliance">     <itemtemplate>         <asp:image id="imgcompliance" runat="server" />     </itemtemplate> </asp:templatefield>      <asp:templatefield headertext="accounting" sortexpression="accounting">     <itemtemplate>         <asp:image id="imgaccounting" runat="server" />     </itemtemplate> </asp:templatefield> 

thanks!

is there way modify data turn these strings booleans? using strings in way strikes me code smell. personally, turn these strings boolean properties of class you're using data source grid , modify visibility properties in markup, rather go database select these properties on row-by-row basis.

regardless of that, yes, can use rowdatabound event this:

yourgrid_rowdatabound(object sender, eventargs e) {     if (e.row.rowtype == datacontrolrowtype.datarow)     {         yourclass currentclass = (yourclass) e.row.dataitem;          (int = 0; < currentclass.stringflags.length; i++)         {             string currentflag = currentclass.stringflags[i];              if (currentflag == "tax")             {                 image imgtax = (image) e.row.findcontrol("imgtax");                 imgtax.visbile = true;             }             else if (currentflag == "compliance")             {                 image imgcompliance = (image) e.row.findcontrol("imgcompliance");                 imgcompliance.visbile = true;             }             else if (currentflag == "accounting")             {                 image imgaccounting = (image) e.row.findcontrol("imgaccounting");                 imgaccounting.visbile = true;             }         }     } } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -