appending data from one column to another column in gridview

 Hi,

I have 2 columns in table..like this,

Area    Areaunit

100       sq.feet

200       sq.yard

400        meters

 

 While showing area in gridview, i want to append its unit . Example 400 meters should be seen and not just 400

<asp:BoundField DataField="area" HeaderText="AREA" SortExpression="area" />

 


Please Mark the post as "ANSWER" if it helps you
0
closeguy2005
1/18/2009 6:26:01 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

14 Replies
724 Views

Similar Articles

[PageSpeed] 44

One way is using template field, check this code.. 

 <asp:TemplateField HeaderText="AREA">
      <ItemTemplate>
            <asp:Label ID="Label1" runat="server" Text="Label">
                   <%# Eval("Area") + "  " + Eval("Areaunit") %>
             </asp:Label>                        
      </ItemTemplate>
 </asp:TemplateField>
 

My Blog


"Don't be afraid to be wrong; otherwise you'll never be right."
0
budugu
1/18/2009 6:45:21 AM

budugu:

One way is using template field, check this code.. 

 <asp:TemplateField HeaderText="AREA">
      <ItemTemplate>
            <asp:Label ID="Label1" runat="server" Text="Label">
                   <%# Eval("Area") + "  " + Eval("Areaunit") %>
             </asp:Label>                        
      </ItemTemplate>
 </asp:TemplateField>

 

 

Hi,

Got this error

: System.FormatException: Input string was not in a correct format.

Source Error:

Line 1187:           <ItemTemplate>
Line 1188: <asp:Label ID="Label1" runat="server" Text="Label">
Line 1189: <%#Eval("area") + " " + Eval("areaunit")%>
Line 1190: </asp:Label>
Line 1191: </ItemTemplate>

 


Please Mark the post as "ANSWER" if it helps you
0
closeguy2005
1/18/2009 6:56:53 AM

this way

<ItemTemplate>

<asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "area") + " " +DataBinder.Eval(Container.DataItem, "areaunit") %>'></asp:Label>

</ItemTemplate>


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
1/18/2009 7:42:34 AM

<asp:TemplateField>
                                                <HeaderTemplate>
                                                   Area
                                                </HeaderTemplate>
                                                <ItemTemplate>
                                                    <%#Eval("Area")%>
                                                    <%#Eval("Areaunit")%>
                                                </ItemTemplate>
                                            </asp:TemplateField>


Thanks & Regards,
Izhar Ul Islam Khan
Microsoft Certified Technology Specialist
0
izharulislam
1/18/2009 7:56:45 AM

Hi, MuddassarKhan

what is the diffrence between  normal <%# Eval("area") %> and DataBinder.Eval(Container.DataItem, "area")

and where we use Databinder.GetDataItem  function

 

 


adilahmed
0
adilahmedmd
1/18/2009 8:10:47 AM

adilahmedmd@gmail.com:

Hi, MuddassarKhan

what is the diffrence between  normal <%# Eval("area") %> and DataBinder.Eval(Container.DataItem, "area")

and where we use Databinder.GetDataItem  function

No Difference when you use in Inline DataBinding as Used Above in the aspx Eval is a new ShortHand of DataBinder.Eval which coming from ASP.Net 1,1

Only difference is you cannot use Eval in CodeBehind while you can use DataBinder.Eval in Code Behind too

For example

1. This will work

Protected Sub GrdRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowDataBound

Dim str As String = DataBinder.Eval(e.Row.DataItem, "CustomerID")

End Sub

 

But

2. This will not work

Protected Sub GrdRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowDataBound

Dim str As String = Eval("CustomerID")

End Sub

 

 


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
1/18/2009 8:26:04 AM

mudassarkhan:

this way

<ItemTemplate>

<asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "area") + " " +DataBinder.Eval(Container.DataItem, "areaunit") %>'></asp:Label>

</ItemTemplate>

 

hi,

got same error for following code:

 <asp:TemplateField HeaderText="AREA">
               <ItemTemplate>

               <asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "area") + " " +DataBinder.Eval(Container.DataItem, "areaunit") %>'></asp:Label>

              </ItemTemplate>
    
              </asp:TemplateField>

 

Input string was not in a correct format. body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px} b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px} H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red } H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon } pre {font-family:"Lucida Console";font-size: .9em} .marker {font-weight: bold; color: black;text-decoration: none;} .version {color: gray;} .error {margin-bottom: 10px;} .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }

Input string was not in a correct format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:

Line 1188:               <ItemTemplate>
Line 1189:
Line 1190:               <asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "area") + " " +DataBinder.Eval(Container.DataItem, "areaunit") %>'></asp:Label>
Line 1191:
Line 1192:              </ItemTemplate>
 


Please Mark the post as "ANSWER" if it helps you
0
closeguy2005
1/18/2009 8:38:50 AM

izharulislam:

<asp:TemplateField>
                                                <HeaderTemplate>
                                                   Area
                                                </HeaderTemplate>
                                                <ItemTemplate>
                                                    <%#Eval("Area")%>
                                                    <%#Eval("Areaunit")%>
                                                </ItemTemplate>
                                            </asp:TemplateField>

 

Superb..this worked smoothly..marking your ANswer


Please Mark the post as "ANSWER" if it helps you
0
closeguy2005
1/18/2009 8:43:31 AM

 Hi closeguy2005,

Are you using VB to code?

If so change '+' to '&'

 

 <asp:TemplateField HeaderText="AREA">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text="Label">
<%# Eval("Area") & " " & Eval("Areaunit") %>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
 
If it still dont work can you mention ur asp.net version? 

Regards,
Naveen

Please remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question.
View Blog
0
naveenj
1/18/2009 8:48:49 AM

closeguy2005:

mudassarkhan:

this way

<ItemTemplate>

<asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "area") + " " +DataBinder.Eval(Container.DataItem, "areaunit") %>'></asp:Label>

</ItemTemplate>

 

hi,

got same error for following code:

 <asp:TemplateField HeaderText="AREA">
               <ItemTemplate>

               <asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "area") + " " +DataBinder.Eval(Container.DataItem, "areaunit") %>'></asp:Label>

              </ItemTemplate>
    
              </asp:TemplateField>

 

Input string was not in a correct format. body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px} b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px} H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red } H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon } pre {font-family:"Lucida Console";font-size: .9em} .marker {font-weight: bold; color: black;text-decoration: none;} .version {color: gray;} .error {margin-bottom: 10px;} .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }

Input string was not in a correct format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:

Line 1188:               <ItemTemplate>
Line 1189:
Line 1190:               <asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "area") + " " +DataBinder.Eval(Container.DataItem, "areaunit") %>'></asp:Label>
Line 1191:
Line 1192:              </ItemTemplate>

I have testedout your same Label in my GridView And I am not getting Any Error

And before Posting I have tested it

For you Reference here's my GridView

<asp:GridView ID="GridView1" AllowPaging = "true" OnPageIndexChanging = "OnPageIndexChanging" AutoGenerateColumns = "false" runat="server" OnRowCommand = "RowCommand" OnRowDataBound = "GrdRowDataBound">

<Columns >

<asp:TemplateField >

<ItemTemplate>

<asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CustomerID") + "--------- " +DataBinder.Eval(Container.DataItem, "CompanyName") %>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>

 

</Columns>

</asp:GridView>

 


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
1/18/2009 9:06:04 AM

mudassarkhan:

I have testedout your same Label in my GridView And I am not getting Any Error

And before Posting I have tested it

For you Reference here's my GridView

<asp:GridView ID="GridView1" AllowPaging = "true" OnPageIndexChanging = "OnPageIndexChanging" AutoGenerateColumns = "false" runat="server" OnRowCommand = "RowCommand" OnRowDataBound = "GrdRowDataBound">

<Columns >

<asp:TemplateField >

<ItemTemplate>

<asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CustomerID") + "--------- " +DataBinder.Eval(Container.DataItem, "CompanyName") %>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>

 

</Columns>

</asp:GridView>

 

 

As Naveen said above, the error I am getting is may be due to I am using VB and your code is for c#. Considering you have tested your code and it works for C# language I am makring your answer too.

For all guys reading this thread, if you are using using C# ,  try the code by MudassarKhan ..while for VB , you can try other post marked as Answer above

Thanks Mudassarkhan..


Please Mark the post as "ANSWER" if it helps you
0
closeguy2005
1/18/2009 10:14:03 AM

naveenj:

Hi closeguy2005,

Are you using VB to code?

If so change '+' to '&'

 

 <asp:TemplateField HeaderText="AREA">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text="Label">
<%# Eval("Area") & " " & Eval("Areaunit") %>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
 
If it still dont work can you mention ur asp.net version?

 

Hi..thanks..

Yes..I am using VB..thread is resolved now

..I have marked correct answers.


Please Mark the post as "ANSWER" if it helps you
0
closeguy2005
1/18/2009 10:19:21 AM

closeguy2005:

As Naveen said above, the error I am getting is may be due to I am using VB and your code is for c#. Considering you have tested your code and it works for C# language I am makring your answer too.

For all guys reading this thread, if you are using using C# ,  try the code by MudassarKhan ..while for VB , you can try other post marked as Answer above

Thanks Mudassarkhan..

Hi CloseGuy I am using VB

And + operator works in VB too

I have given you VB one itself since I have seen you working in VB in past posts

I dont know why ae you getting Errors

 See below

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim dt As DataTable = GetData("SELECT * FROM Customers")

GridView1.DataSource = dt

GridView1.DataBind()

End Sub


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
1/18/2009 10:24:05 AM

 If this is the case, then I wonder..

but anyways.

..good to know it works for VB too..

 


Please Mark the post as "ANSWER" if it helps you
0
closeguy2005
1/18/2009 10:46:26 AM
Reply:

Similar Artilces:

Displaying one of the columns in GridView data as GroupBy or similar data one after another row
Hi Would like to know the property or code that will Group data in one of the columns of GridView together. In other words i like to display the columns data in GridView that is repeated more than once together. Example: say Column heading Name John Jim Kevin Albert John Jim John You can see john or jim is displayed in Name Column at various rows. I like to get them displayed together such as John John Jim Jim Regards,-- "Mark As Answer" if my reply helped you -- Hi I am not too sure, but may be you can try a "Order by" clause at your SQL level. Say,...

Copy Data From One Datagrid Column To Another Column
Hi all, I am trying to copy data from one column in a datagrid to another column in the same datagrid. I am using buttons to do this, not the edit, update, cancel datagrid buttons. This is what I have been trying but with no luck :int RowCount;RowCount = 1;string DataValue;//while (RowCount < DataGrid1.Items.Count)//{// DataGrid1.SelectedIndex = RowCount;// DataGrid1.SelectedIndex = RowCount;// DataValue = DataGrid1.SelectedItem.Cells[4].Text;// DataGrid1.SelectedItem.Cells[3].Text = DataValue;} Help appreciated thanks. Try this <%@ Page Language="C#" %&...

Move data from one column to another column and row
I need some help converting a table which has one row for each year.  Displaying the data so the each row will contain all of the information for the title and all of the years displayed in separate columns. I have a SQL Querry which returns the data looking like this (the querry is grouping by Title and by year, then adding up the quantity of rows): Basic Information needed for Life Insurance 25 2005 Basic Information needed for Life Insurance 45 2006 Ea Chairmans Conference 10 2005 EA Chairmans Conference Press Release 33 2005 EA Chairmans Conferenc...

Calculate a column in a Gridview based on data in another column of the same Girdview?
Anybody got any ideas? I'm stumped. I want a column in a gridview to take the value of another column in the same row as a parameter and run a query and then bind it. Like I said I'm stumped.   Bill I don't think you can pass the value of another column in the same row as a parameter and run a query and then bind it.  However, you could write a query with a calculated column from another field.  LynnPlease mark replies that have helped you as answers. Hi CoreslabBill, You can do it in RowDataBound event of GridView control. Here is my sample. In my samp...

populating a column in one table with data in a column from another table?
Hi,I have one main table and multiple smaller tables, the main table consists of all the information gathered from the smaller tables, plus some other data. I've set primary keys for all the smaller tables and created a relationship where the primary key id matches an id field inside the main table eg. there's a smalltableid column in both the smaller table and the main table.some misc info:i'm using a dataset (should the key in the dataset be pointing to the main table, or the smaller one?)both relation and foreign key constraints are created (with no rules set)my problem is, the data from ...

Data presentation control in another Data presentation control
 Hello,I want to make a menu with datalist or gridview control.Basically,the menu will be like this,Categories     Sub Categories.For example, for COMPUTING category there will be NOTEBOOKS DESKTOPS etc.There will be a image for CATEGORIES and linkbuttons with Subcategories.If I put a datalist inside a datalist and a link button inside the second datalist visually it satisfies my need.However,CommandArguments come from database to linkbutton.Andwhen one of these command buttons is cliked it must go to proper page.I dont know how to wrie an event_handler ,specifically, for...

Gridview edit How to subract one column from another show result in 3rd column.
If a user edits ShippingWeightGr or ShippingWeithTr I need it to subtract ShippingweithGr - ShipingWeightTr and put it in the ShipingweightNet.       How can I do this?  Here is my gridview code     <asp:GridView ID="GridView1" runat="server" AllowPaging="True"             AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Id"             DataSourceID="SqlDataSource1...

Issue with Template Columns & Bound Columns while updating the data in a GridView control
Hi, I'm facing the below problem (In general, ObjectDataSource is driving me crazy ! ) I have a simple gridview control and an ObjectDataSource is used to populate the grid. I'm trying to update a row and the corresponding tableadapter methods & stored procedure are in place. Each row has 2 checkboxes and 2 textboxes in edit mode. When the change the values in edit mode and hit update, the checkbox values changed are saved into the Database properly, whereas the textbox values are not being saved. If the textbox column is a bound column then the column is updated with <NULL> in...

How to manipulate images and combe multiple database columns into one column in a GridView control
Hi Folks,I'm hoping someone can help me out with something.I am trying to put together a photo album as a learning exercise and have a GridView control with two columns linked to an Access Data Source. In the left hand column (called Image) I want to display the photo and in the right hand column (called Details) I want to provide details such as Date, Location, People and Comments, Camera Type etc. Each of these is columns is taken from the database I have set up.However, I have am having some problems:1: At the moment I have been able to get the image to display (using an image column ...

i have work on gridview control.in that i have 3columns.name as subject,bookname,link. in this some link column data are very large.according to that data(no spaces in that data)gridview has changed.i
hi,i have work on gridview control.in that i have 3columns.name as subject,bookname,link. in this some link column data are very large.according to that data(no spaces in that data)gridview has changed.i want display half of the data and remaining display like this.(ex:http://ww.yahoo.com...........).how can i display like this,and one more thing is always the column size will constant. Try something like this: <asp:templatefield headertext="Link"> <itemtemplate> <asp:hyperlink id="HyperLink1" runat="server" navigateurl='<...

binding a gridview to xmldatasource gives "The data source for gridview gridview1 did not have any properties or attributes from which to generate columns. Ensure that your data source has columns
Greetings!  I am new to asp.net forum so feel free to point me to the proper resources or forums.  I am using Visual Studio 2005.  I have a simple web page with a gridview control and an xmldatasource control.  I am getting the above error.  Can someone point out why I am getting the above error and what I need to do to resolve it?  Thanks in advance. /////////////////////////////// default.aspx  <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="default.aspx.vb" Inherits="XMLwalkthroughVB._default" %&...

Is there a control that offers the same data presentation as a GridView, but allows users to copy and paste many rows/columns at once?
 Hi Is there a control that offers the same data presentation as a GridView, but allows users to copy and paste many rows/columns at once onto the grid? What I mean is some grid that 's as flexible as MS Excel grid for example.  Any suggestions will be very much appreciated.E The Repeater control is a highly customisable data presentation controlRohin.NET developerNever trust a computer you can't throw out a window. - Steve WozniakPlease remember to click on 'Mark as answer', if this post helped you......

Grouping two columns into one column with GridView
I would like to modify the default output of a gridview to group two columns into one column. This is probably best explained by example. So, lets say there is a simple gridview with the output something like this:Name           Description                           Date------------------------------------------------------------------Foo            Some description of foo     &nb...

Passing value from one column to another column
Hi friends, I have  two drop down list controls in the Grid view control.I bound the data from data base.My problem is:             When i select value from first drop down list, the corresponding second drop down list generated  according to the  value selected in first drop down list.Please help me Regards.   Akhil   Regards,Akhil Raj K.R.Collaboratz. The Ajax Control Toolkit has a drop down list extender to use.  Goto http://www.asp.net/ajax/ajaxcontroltoolkit/  and review the C...

Web resources about - appending data from one column to another column in gridview - asp.net.presentation-controls

Google Appending URLS With GWT & PG?
A WebmasterWorld thread spotted, I believe, referrals from URLs that have _gwt_pg= appended to the end of the URLs. So what does the GWT and ...

Appending Larry
A recent Reuters article on Google's prematurely released earnings report noted that a Twitter parody account was created to mock the "PENDING ...

The readers' editor on… appending notes to stories if errors may have been made
Chris Elliott: Open door: This device seems fair if the evidence is not conclusive but a strong case has been made – but not all complainants ...

Google Appending Brand In Front Of Search Results Title
Typically, when Google shows a clickable headline in the search results...

Resources last updated: 12/13/2015 11:07:55 AM