GridView Question

P

Paul

I have a grind view which I bind to a dataset. I only show specific
columns from the dataset, but i need to reference the keyfield from
the DS to calculate the value of other fields. I have a custom field
which contains a label. Using the OnPreRender event, I need to access
the datasets keyfield - it needs to be passed into a function, which
returns a string which I need to assign to to the labels Text
attribute. I can currently do this with #EVAL but I want to know if
there is a simplier way? I'm currently assigning doing the following:

<ItemTemplate>
<asp:Label Text='<%# Eval("idMeeting") %>'
OnPreRender="lblReviewee_OnPreRender" runat="server" />
</ItemTemplate>

in the OnPreRender event, I assign the value to a string, then pass
this string into a function, assigning the output to the
((Label)sender).Text attribute.
THis seems a little convoluted. Is there a simpler way of doing this?

Any help would be appreciated.
 
G

Guest

Hi Paul,

Do it directly:

<ItemTemplate>
<asp:Label Text='<%# FunctionYouUseInPreRender(Eval("idMeeting")) %>'
OnPreRender="lblReviewee_OnPreRender" runat="server" />
</ItemTemplate>

I don't know what the type of the paraneter is but you'll have to cast it
before passing (i assume it's int) :

<ItemTemplate>
<asp:Label Text='<%# FunctionYouUseInPreRender((int) Eval("idMeeting")) %>'
OnPreRender="lblReviewee_OnPreRender" runat="server" />
</ItemTemplate>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top