.NET C# - Datagrid inline code...

Soldato
Joined
17 Jul 2005
Posts
3,193
Hi Guys,

I've got a datagrid that is bound at runtime to a table adapter query.

The query returns a user id amongst many other items. A snippet of the first two lines is below...

Code:
<asp:TemplateField HeaderText="User"><ItemTemplate><asp:Label ID="lblUsername" runat="server" Text='<%=test;%>'></asp:Label></ItemTemplate></asp:TemplateField>
            <asp:BoundField DataField="age" HeaderText="Age" />

Now the database only stores the user id. I then elsewhere been using that user id to grab a GUID from a users table and then using the GUID to return a display name from an Active Directory query.

I want that display name to display to display in the above datagrid and thought a template field would be the way forward?

Can this be done? Can I call a method using code tags in the label control, pass the user id from the gridview values and then return and response.write?? the value to the page?...

I apologise if i've explained myself poorly! One solution I've thought of is to just store the full display name in the database and just sync it each evening. The reason I haven't been storing the display name is in case it gets changed in Active Directory.

Many Thanks,
 
yes you can :D

template fields are a way to do this then use the databinder

something like this

Code:
<asp:TemplateField HeaderText="Player Name">
    <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# GetDisplayName((String)DataBinder.Eval(Container.DataItem,"xxxxxx"),%>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>

getDisplayName = your method to return display name and the xxxxx is the name of the user id field.
 
Back
Top Bottom