Thursday, March 22, 2012

Newbie how to connect to data field together

I have a gridview which has VS 2.0 C#

First name , last name and phone number in different colums I would like to combined the first name with the last name putting the last name first.

Example what I have John | Doe | 555-5555 |

What I want Doe,John | 555-5555 |

any one can tell me how to do this?

you can use a format like this:

<

asp:GridViewID="GridViewProperty"runat="server"AutoGenerateColumns="False"DataKeyNames="Id"DataSourceID="ObjectDataSource1"><Columns><asp:TemplateFieldHeaderText="Full Name"><ItemTemplate><asp:LabelID="Label1"runat="server"Text='<%# Eval("Address") + " " + Eval("City") %>'></asp:Label></ItemTemplate></asp:TemplateField>

Change it to a template column and add the fields under that. Or if you got the dataset you can use that to create an string

string sAllfields = dataset.Table[0].Row[0][1].ToString() + dataset.Table[0].Row[0][2].ToString() + dataset.Table[0].Row[0][2].ToString();

0 comments:

Post a Comment