How to perform functions upon 'bound' data? (asp .net)

M

murdock

Is there a way to perform functions upon databound data that is to be
used in a GridView? For example, in the following code where I am using
a GridView to display a resulting asp:SqlDataSource

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4"
DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None" Height="402px" Width="612px" AllowSorting="True"
PageSize="50">
<FooterStyle BackColor="#990000" Font-Bold="True"
ForeColor="White" />
<Columns>
<asp:BoundField DataField="Field1"
HeaderText="Field1" SortExpression="Field1" />
<asp:BoundField DataField="Field2"
HeaderText="Field2" SortExpression="Field2" />
<asp:BoundField DataField="Field3"
HeaderText="Field3" SortExpression="Field3" />
<asp:BoundField DataField="Field4"
HeaderText="Field4" SortExpression="Field4" />
<asp:BoundField DataField="Field5"
HeaderText="Field5" SortExpression="Field5" />
</Columns>
<SelectedRowStyle BackColor="#FFCC66" ForeColor="Navy"
Font-Bold="True" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
</asp:GridView>

Is there something in Visual Studio 2005 Express Edition on the control
itself (somewhere in the properties) to perform an 'action' on a field
prior to insertion?

For example, if you have something formatted oddly in the dataset, and
you have a string Field1 in format "abcdefg" and you wanted to strip
"efg" before putting it into the gridview in the appropriate column.

Regards,
MurdockSE
 
N

NathanJ

I am not totally sure about using functions in a gridview. You can
however use functions for your bound data in a datagrid or datalist.
<%# Function(container.dataitem("Field1"), myParam) %> like so. Not
sure if this helps.

-Nathan
 
G

Guest

Hello MurdockSE,

You should be able to add an event handler for the RowDataBound event of the
GridView control to access row data after it is bound and before it is
rendered. Something like this:

void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{

if(e.Row.RowType == DataControlRowType.DataRow)
{
// Display the company name in italics.
e.Row.Cells[1].Text = "<i>" + e.Row.Cells[1].Text + "</i>";

}

}
 

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,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top