c# - asp.net - Bind to a linq datasource and add external column -


i have databound control displays grid. grid bound linq sql data source. use following code:

paymentsdatacontext data = new paymentsdatacontext();             var q = act in data.activations                     act.approved != true                     orderby act.activationdate ascending                     select new {activationid = act.activationid, username = act.username,                     brokername = act.broker.brokername, existingaccount = act.existingaccount,                     activationdate = act.activationdate, brokeruser = act.brokeruser, approved = act.approved};             activationpending.datasource = q;             activationpending.databind(); 

i want add column grid. want show user's email address. so:

var member = system.web.security.membership.getuser(username); string email = member.email; 

how add field in grid, since it's not in payment db @ all?

try this:

var q = act in data.activations                     act.approved != true                     orderby act.activationdate ascending                     select new {activationid = act.activationid, username = act.username,                     brokername = act.broker.brokername,                      existingaccount = act.existingaccount,                     activationdate = act.activationdate, brokeruser = act.brokeruser,                     approved = act.approved,                      email = system.web.security.membership.getuser(act.username).email }; 

since bin q , not data.activations adds external column grid.

edit : because of new added column template of grid view must have place accept can add manually :

<asp:gridview id="gridview1" runat="server" autogeneratecolumns="true"> <columns> . . <asp:boundfield datafield="email" headertext="email"              sortexpression="email" /> . . </columns>  </asp:gridview> 

or set property of gridview named autogeneratecolumns true

<asp:gridview id="gridview1" runat="server" autogeneratecolumns="true">     </asp:gridview>  

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -