How can I add 2 fields value to 1 fields value in a GridView?

Hi all!

I have one access database named=Medlemmar.mdb and Tablename=TidBokning and with some columns ex. "Bokad_For" and "Plats".
Let say that "Bokad_For" contains value "Group2" and "Plats" contains value "Stockholm".
Now I want to make this 2 value to 1 fileds like this: "Bokad_For" contains value "Group2Stockholm"
How can I do that?
I use asp.net 2.0 and C#.
I tried with Eval("Bokad_For") and somthing, but Eval works only in Templates (I guess) I cant get Templates to work in my GridView.
i'm newbee in this and think I need some help here :-) ?

Thanks for all help!

Micael Roxenhall
0
roxenhall
1/4/2007 8:30:03 AM
asp.net.getting-started 91979 articles. 4 followers. Follow

4 Replies
714 Views

Similar Articles

[PageSpeed] 45

You can solve it easy with templates and the Eval expression (there are other solutions also, but this one is easy and fast to implement).

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" ...>
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>


<asp:Label ID="Label1" runat="server" Text='<%# String.Format("{0} contains value {1}[2}",Eval("Bokad_For"),Eval("Grupp"),Eval("Plats")) %>'></asp:Label>


                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

 


/Fredrik Normén - fredrikn @ twitter

Microsoft MVP, MCSD, MCAD, MCT

ASPInsiders
My Blog
0
Fredrik
1/4/2007 9:22:19 AM

2 ways..

1. make your SQL statment as 1 field, such as SELECT A + B as 'AB' from TblAB

2. let 2 BoundColumns Visible to false, and make ItemTemplate to combined those two boundColumns

such as

<asp:BoundColumn DataField="A" HeaderText="A" Visible=False></asp:BoundColumn>
<asp:BoundColumn DataField="B" HeaderText="B" Visible=False></asp:BoundColumn>
<asp:TemplateColumn HeaderText="AB">
<ItemTemplate>
<asp:Label ID="lblAB" runat="server" Width="100%" Font-Size="9pt"></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>

 In the code behind, at Gridview's ItemDataBound event

you can ((Label)e.Item.FindControl("lblAB")).Text = e.Items.Cells[0].Text + e.Items.Cells[1].Text //e.Items.Cells[0] is A field, Cells[1] is B field

 

Happy Coding

 


James Wu (MIB426)
.NET is only way to go
MCP, MCSE, MCDBA, MCSD, MCAD
0
MIB426
1/4/2007 9:23:13 AM
You need to convert the column as TemplateColumn first.

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" ...>
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("Bokad_For") + Eval("Plats") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

Thanks 



Mark post(s) as "Answer" that helped you

Electronic Screw
Website||Blog||Dub@i.net
0
e_screw
1/4/2007 9:40:12 AM
Thank You ALL for your quickly help!

That resolve me problem!

Thank you all that you take your time with me!

Best Regard

Micael Roxenhall
0
roxenhall
1/4/2007 12:00:09 PM
Reply:

Similar Artilces:

Gridview Hyperlink Field needs to include value from a previous gridview and a field value
Hi all Hope you can help, here is what I'm trying to do. I have a gridview on a page that contains a value (PracticeCode) I use this value as a parameter to filter an additional GridView (Gridview2). Now what I also want to do is take that value (PracticeCode) and use it in as part of the URL for a hyperlink field in GridView2 concatenatint it with the value of a Gridview field called Documentname so that: Hyperlink field URL Is "/store/" & PracticeCode & "/" and DocumentName Anyone know how to do this  regards chubsterit wasn't me, ...

Single Value Field to MultiValue Field - Reverse Multi to Single storing all Values
begin 644 rule.txt M"3QR=6QE/@T*"0D\9&5S8W)I<'1I;VX^57-E<B`M(&-O;G9E<G0@;75L=&DM M=F%L=65D($1E<V-R:7!T:6]N('1O('-I;F=L92!V86QU92`F;'0[)FQT.R!S M97!A<F%T960\+V1E<V-R:7!T:6]N/@T*"0D\8V]N9&ET:6]N<SX-"@D)"3QO M<CX-"@D)"0D\:68M8VQA<W,M;F%M92!O<#TB97%U86PB/E5S97(\+VEF+6-L M87-S+6YA;64^#0H)"0D)/&EF+6-L87-S+6YA;64@;W`](F5Q=6%L(CY'<F]U M<#PO:68M8VQA<W,M;F%M93X-"@D)"3PO;W(^#0H)"0D\;W(^#0H)"0D)/&EF M+6]P+6%T='(@;F%M93TB1&5S8W)I<'1I;VXB(&...

DetailsView: conditionally hide field if value == null, but can't update the value of other fields
Hi, I need help please. I have made some fields hidden if their value is null by setting visible to false on the DetailsView1_Itemcreated event. I put the field's to the DataKeyNames, so that I can check the value is null or not when detailsview is at the readOnly mode.But, when I tried to edit, it throws an error: must declare a scalar for @...  so, i add some code in the DetailsView1_ItemUpdating: e.newValues["color"] = null; then the error is gone. but, the values for other fields are not updated. I already check the e.newValues["other fields"] , they all are ...

Single Value Field to MultiValue Field - Reverse Multi to Single storing all Values
Hi All I have implemented a rule that converts the multivalued Description field to a single valued field in AD (See Attached rule) James Miller - Dec 2004 << Mario Kardum - 10 Feb 2004 << Amanda Saintsbury - June 2005 << The result is as above All good so far. Now I want to create a rule to break up and replace the single value field above to a EDir multivalue Field James Miller - Dec 2004 Mario Kardum - 10 Feb 2004 Amanda Saintsbury - June 2005 I presume I need to use XPATH to create the Multivalue entries Does anyone have an idea? Regards ...

How to get the value of a textbox that has been added to a template field in a gridview. VB.Net
I have a gridview that shows products, description, price. I have added a Buttonfield and a TemplateField that has a Textbox with the id QuantityTextBox.What I am trying to do is get the value of the Quantity TextBox in the RowCommand event of the gridview. I can get the price but need to get the quantity also. To get the price I used ItemPrice = Server.HtmlDecode(row.Cells(5).Text) My template field is cell 6 but the above routine does'nt work. Any help would be greatly appreciated.Dan5150www.5150creations.com Hiuse this: VB:  Protected Sub GridView1_RowCommand(ByVal ...

How do I get the Identity field value after a sql insert so the value can be included in the email sent upon submit?
I have  a form that gathers a bunch of data, inserts into a sql database via a stored procedure, and then emails a user some details.  How can I include the value of the unique identifier for the row just inserted into sql in the email?    Here's my code behind.. and I don't know how/where to query the db to get the value and insert it... Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit.Click InsertConflictSearch.InsertParameters("SearchStatusID").DefaultValue = "1"InsertConflictSearch.Insert...

Datagrid(.net 1.1) to GridView(.net 2.0) and using the RowUpdating event how to extract the values from the controls.
Ok  This is the settings: I use a Viewgrid with only itemtemplate colums for example. <asp:TemplateField HeaderText="Test"><ItemTemplate><asp:Label id="LBL_Test" text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' runat="server" meta:resourcekey="LBL_TestResource1"></asp:Label></font></ItemTemplate> <EditItemTemplate><asp:TextBox ID="HDN_Test" Text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' Runat="server" meta:resourcekey="HDN_TestResource1" /></EditItemTemplate></asp:TemplateField>  The ...

How to get the value out of a field from the gridview
Hi, I have a gridview with 2 bound fields, 1 template field with a textbox, 1 template field with a dropdownlist. I need to pass that 1 bound field, textbox template field, and dropdownlist template fields as parameters to a procedure (updating or whatever it needs to do). So, how can I obtain the values out of them for the row that I just edited to become parameters to pass it to a procedure? I am using VS2005 C#. I can get the values if they were in the edit mode, but not AFTER (when gridview1.editindex = -1). Any help/input would be appreciated. Thanks.   ...

Selecting value in one field then causes value in another field to be selected.
I have a web form which contains a date field, the date is populated using a DatePicker which is Javascript based. The form also has a drop down box containing 3 values. What I want to do is when a date has been selected that this will cause the dropdown list value to change to dated which is one of its 3 values. i.e. when the date field is not blank then the value will be selected in the dropdown. What I also want to happen is when the date has been selected and the dropdown value is dated then the date field and the dropdown field will be set to read only.Anyone any ideas how to this usin...

How can I have 2 dates and select all records that have a date field with a value between those 2 dates?
I have 2 textboxes, 1 for the start date and 1 for the end date and I want the user to be able to enter 2 dates and select records from SQL that fall between those 2 dates. I have the code working in classic asp but am getting an error with .net. This is the code i have: Dim enddate As Date Dim startdate As Date enddate = Request.form("date_from") startdate = Request.form("date_to") strSelect = "SELECT id, title, category, dateadded FROM news WHERE category = 'articles' AND dateadded BETWEEN '" & startdate & "' AND '" &...

Way to get Original value of the field into computed field
Hello, My Environment is PB10. Is there any way to get the orinal value (Similar to the Original buffer value in olden days) of the field into computed field. Thanks, Sra "Sravan" <sr.100102@gmail.com> wrote in message news:121a4797-cc11-4927-8613-ba3f69a6e009@e31g2000vbm.googlegroups.com... > Hello, > My Environment is PB10. Is there any way to get the orinal value > (Similar to the Original buffer value in olden days) of the field into > computed field. Just add ".original" to the column name. E.g., transaction_date.original ...

Displaying an image in gridview field dependant of field value
Firstly I apologise in advance for my lack of knowledge, this is what I'm trying to achieve: I have a gridview (orders) that is populated based on a selection in another (customer), one of the fields is orderStatus this is an integer (0=outstanding, 1=in progress 2=complete) instead of displaying the integer value in my grid I would like to display an appropriate icon. I have managed to get the value of the field using:1 Protected Sub order_Rowcreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles order.RowCreated 2 If e.Ro...

add text field values to gridview
Please disregard...I found what I needed.  Thank you.    I have a gridview and I'm not binding any database records to the gridview, but I want to manually add two text field values to the gridview on a click event.Is this posible?  If so, is there an example of how to do this?Thanks in advance for any help. Sure this can be done.I have provided a quick sample but I shall leave the task of you keeping the state of it after adding each row each time you click add. The idea is as follows.On page load or when you want to load this gridview, we add an empty ...

Get value from template field on GridView
 I am trying to retrieve the value of a template field, here's the code I used to bind the data  <asp:TemplateField HeaderText="End Date"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("End_date", "{0: MM/dd/yyyy}") %>' Width="90px"></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("End_date&q...

Web resources about - How can I add 2 fields value to 1 fields value in a GridView? - asp.net.getting-started

GridView SelectedItem Binding Gotcha in WinRT
Last night when I was doing some WinRT hacking I was trying to setup databinding to the selected item in the GridView control and I ran into ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Advanced Search Gridview Latest News Releases All ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Gridview ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Add a Filter Gridview Latest News Releases All Today ...

New CmdLets of Powershell 2.0
New CmdLets of Powershell 2.0

Price Drop: Softbox
... objects- create product reflection- changing the background with something more interestingUse it as:- softbox- honeycomb softbox- gridview ...

Profile.aspx: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 25 Oct 2012

DotNetKicks.com - Upcoming stories
DotNetKicks.com is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

View Features - ExtendASP
Call 847-681-9827 or Request a Demo View Features Testimonials Pricing About Us Coming Soon ExtendASP exposes every feature, more than any other ...

Resources last updated: 12/24/2015 12:34:55 AM