Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 12, 2012 01:26 PM by rcast
Jun 10, 2012 06:20 AM|LINK
Hi, I am stuck on how to assign values on a label or text box.
The issue is the following:
I have two tables, one called A and the second one called B
Table A has tree fields: id, name, lastname
Table B has five fields: id, level1, level2, level3, level4
The idea is to save A.id into level1, level2, level3 and level4. A.id can be the same or not. I know how to assign and save the values on the DDBB using DDL, but when I want to show the values using labels, I get the first value always, this is becuase the
select command is configures in that way. If I use ddl instead label, it works, but I do not want to show the value using ddl. I want to use label to show the values, and ddl to modify or add new data into the DDBB.
I am using <griedview>.
The code is as follow:
<asp:TemplateField HeaderText="Level 1" SortExpression="name">
<ItemTemplate><asp:Label ID="lblLevel1" runat="server" width="100" Text='<%# Bind("name") %>'></asp:Label></ItemTemplate>
<asp:TemplateField HeaderText="Level 2" SortExpression="name">
<asp:DropDownList ID="ddlLevel2" runat="server" width="100" DataSourceID="sqlDSA" DataTextField="name" DataValueField="ID" SelectedValue='<%# Bind("level2") %>'></asp:DropDownList>
SelectCommand="SELECT * FROM B WITH (INDEX (IX_B)) LEFT JOIN A ON B.level1 = A.ID"
<asp:SqlDataSource ID="sqlDSA" runat="server" ConnectionString="<%$ ConnectionStrings:psCS %>"
SelectCommand="SELECT * FROM A">
As you can see the level1 uses label, and level2 uses ddl, it was the only way to get the value for level2, otherwise if I use label on level2 it display level1 value instead.
I would like to know if there is any way to assign different value using anything but ddl.
Maybe I have to work on the Select command, but I do not how.
Jun 10, 2012 07:33 AM|LINK
I suppose you want to bind multiple columns values to a single label control.
You can combine those columns in SQL abd give it a column name and then bind that column name to your label.
SELECT level1 + ' ,' + level2 + ' ,' + level3 + ' ,' + level4 AS CombinedLevel FROM Table
Then bind the CombinedLevel to your Label
Jun 10, 2012 11:49 AM|LINK
I have for columns, and each column usign its own value. Column one = value1, column two = value2, and so on.
lblLabel1 = tableB.name
lblLabel2 = tableB.name
lblLabel3 = tableB.name
lblLabel4 = tableB.name
but each lblLabel# has or not same ID from tableB
I would like to use label instead to use ddl to show the info. I will use ddl to modify and add new values. It works, but label works only with value1.
table A has ID and names. table B has table A IDs only.
Tks for your support.
Jun 12, 2012 03:58 AM|LINK
Someone can help me on this?
I will try to explain the situation in another way to simplify the question.
Table A has ID and name
Table B has level1 and level2
b.level1 = a.ID
b.level2 = a.ID
I wanto to display a.name using a label command, but seems like label is able to get the first value since I am doing join on A where a.ID=b.level1
I do not know how to get b.level2=a.ID at the same time b.level1=a.ID
it is like:
a.ID = 1
a.name = "John"
a.ID = 2
a.name = "Maria"
b.level1 = 1
b.level2 = 2
using label with level1 and 2:
eval("level1") it shows 1
eval("level2") it shows 2
using label with name:
eval("name") it shows John
eval("name") it shows John (here I need to shows Maria instead)
Jun 12, 2012 01:16 PM|LINK
Rather add an ID to the to the table A to link the two tables and select from the table a and then retrive for Table B
Jun 12, 2012 01:17 PM|LINK
or you could create a view and select form a view.
Jun 12, 2012 01:26 PM|LINK
Hi. Table A has a field called ID. Both table are linked, but the second label get always the value of label one.