How can I databind to a DataGrid Column?

D

Dominic

Why is there no databinding for the properties of a datagrid column?
I have a scenario where the FooterText property of a column is the
result of a function. How do I, or why can't I databind the value to
the property? I know I can set it on the code page, but if there is a
way to create a datagrid column where I can bind properties it would
be preferred.
 
M

Michelle Hlaing

Hi Dominic,

If you knew the column that you wanted to set the footer text for, you can do so by:

DataGrid1.Columns[0].FooterText = <string>

where 0 is the first column in the datagrid.

If you wanted to dynamically bind each column to specific properties, you can try using template columns. Have you looked at that?

Hope that helps,

Michelle

***Disclaimer: This posting is provided "as is" with no warranties and confers no rights.***
--------------------
 
D

Dominic

Michelle, thanks for the response. I'm familiar with both of these
implementations, and eventually had to 'hack' one of them out. Why
can't I or how do I implement a design-time FooterText='<%#
myFunction()%>'. Would seem the more intuitive way to do it.
 
M

Michelle Hlaing

Hi Dominic,

Off hand, I'm not sure why but I'll look into it and get back to you next week.

Regards,

Michelle Hlaing

Microsoft Support Professional

***Disclaimer: This posting is provided "as is" with no warranties and confers no rights.***
--------------------
 
M

Michelle Hlaing

Hi Dominic,

I believe that if you used TemplateColumns, under the FooterTemplate where you have your label, you can do this:

<FooterTemplate>
<asp:Label id=Label16 runat="server" Text='<%# myFunction() %>'>
</asp:Label>
<FooterTemplate>

Because all these functions get loaded up at the time of creating the page, you should at least return an empty string at the beginning so there is a valid
value that the Text field can bind to.

Hope that helps,

Michelle Hlaing

Microsoft Support Professional

***Disclaimer: This posting is provided "as is" with no warranties and confers no rights.***
--------------------
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top