I am using DayPilot which has two attributes DataValueField and DataIdField. Both are assigned with some values. I can access DataIdField in Code behind using e.Value but cannot access DataValueField.
Are these same things or they are different ?
Please help
Same as my other answer:
As seen on this link the DataValueField is obsolete:
Gets or sets the name of the column that contains the id (primary key). Obsolete. Use .DataIdField instead.
In my project I can access the value this way:
DataValueField="id" //column "id" of my source table
Get it in BeforeEventRender:
string id = (string)e.DataItem["id"];
Related
I have a table called claims which has an id called currencyId of datatype INT.
Then also a table called tblCurrency with primary ID of currencyId.
And then had an association which was fine. Then in Linq I could use
<%# ((claim)Container.DataItem).currency.value %>
But now I have to add another INT column to tblClaims called finalCurrencyID which I also want an association with to tblCurrency.
Just wondering how I could achieve this, so at the moment ((claim)Container.DataItem).currency.value is linking up claim.currencyId to tblCurrency.currencyID and getting tblCurrency.value.
But how could I make it more flexible so I can determine which currencyID from tblClaims to call?
If I read the right, I think you are looking for this:
<%# ((claim)Container.DataItem).finalCurrency.value %>
Assuming, of course, that you've wired up claim to have a L2S FK to finalCurrency.
Using an SQLDataSource, how do I update entries by the uniqueID key? It's a simple question but I am soooo confused! I need to edit a value named "pageContent". It is the value that I need to update!
Cheers!
EDIT
This ones for you Jorge:
[key] id/int (No Nulls)
pageContent/nvarchar(MAX) (No Nulls)
Current Content:
[ id ] [ pageContent ]
1 <b>test</b>
2 test
SqlDataSource is used to bind database data to controls on web page and not to preform direct operations on database.
If you just need to update one column in table on given key, consider using System.Data.SqlClient.SqlConnection class to connect to db and System.Data.SqlClient.SqlCommand class to execute sql statement.
EDIT:
Example of use very similar to your case is in SqlCommand.Parameters help: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.parameters.aspx
I have two SQL Server tables with Primary Keys (PK) and a Foreign Key (FK) linking the two tables:
1) Table "Order"
OrderID, int, PK
AddressID, int, FK
...
2) Table "Address"
AddressID, int, PK
City, nvarchar(50)
...
Then I've created an (ADO.NET) Entity Data Model out of those two tables.
Now on my (ASP.NET) webpage I put a GridView with an EntityDataSource. In my GridView I want to display two columns:
OrderID
City (belonging to that order and linked by the AddressID-key)
How can I do that? My problem is: When I configure the Entity Data Source I can select an "EntitySetName" which can be
either "Order" or "Address" but not both, nor can I select any kind of relationship. If I select "Order" as EntitySetName
then in the GridView I can add the columns
OrderID
Address
Address.AddressID
Adding the column "Address" displays empty cells. Adding "OrderID" and "Address.AddressID" displays the expected IDs. But how can I
add the "City" of the related address to my GridView?
Thank you for help in advance!
Edit: Clarification:
The Entity Framework has created a class "Order" and a class "Address" corresponding to the database tables. The class "Order" has a reference to an "Address" object as a navigation property, corresponding to the 1-n relationship between Address and Order table.
Basically I want to have a column in my GridView which displays Order.Address.City. I have tried to add a bound field with "Address.City" as data field to the GridView but it results in a runtime error ("no such property...").
OK, much too many hours later I found the solution myself:
Option 1:
It is possible to use the select property in the EntityDataSource which allows to create arbitrary projections of data from several related entities/database tables (in my case: OrderID from Order entity and City from the
Address entity)
Drawback: Using select in the EntityDataSource makes using Insert, Update and Delete in the GridView impossible!
Option 2:
The EntityDataSource must have the include property to include the related address property along with the queried orders. The markup looks likes this:
<asp:EntityDataSource ID="EntityDataSourceOrders" runat="server"
ConnectionString="name=MyEntitiesContext"
DefaultContainerName="MyEntitiesContext"
EntitySetName="Order" Include="Address"
EnableDelete="True" EnableInsert="True"
EnableUpdate="True">
</asp:EntityDataSource>
Then the columns collection of the GridView can have a template field like this:
<asp:TemplateField HeaderText="City" >
<ItemTemplate>
<asp:Label ID="LabelCity" runat="server" Text='<%# Eval("Address.City") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
Here Eval is important. Bind does not work. Also using a BoundField as a column...
<asp:BoundField DataField="Address.City" HeaderText="City" />
... is NOT possible. So it is not possible in the GridView to edit the City (which makes sense because its a related field belonging to another table and perhaps to many other orders). But it is possible to edit flat fields of the order entity and also the "AddressID" of the order to assign another address.
I have a sqldatasource connection in whose parameters, the insert parameter is set as
INSERT INTO [user_info] ([firstname], [lastname], [age]) VALUES (#firstname, #lastname, #age)
Now i understand #firstname, #lastname, #age are the parameters to which i set them the value.
I'm databinding it with a formview, which automatically binds the textbox in the insertitemtemplate with the columns Firstname, lastname and age respectively. For instance the FirstName Text box has the following property.
<asp:TextBox ID="firstnameTextBox" runat="server" Text='<%# Bind("firstname") %>' />
Now my doubt is that, the #firstname variable how is bound with the firstname field. I have not explicitly used the binding anywhere. Say tomorrow i want to rename the insert query as
INSERT INTO [user_info] ([firstname], [lastname], [age]) VALUES (#fn, #ln, #ag)
where and all i will have to make changes inorder to bind #fn with FirstName and so on.
Hope my question is clear.
Short Answer: changing your parameter names won't cause a ripple effect. Changing your column name will.
Detailed Answer: Databinding with Bind (and Eval) in this case applies to the column name of your SQL table, not the parameter name. If you were to start using the 2nd INSERT statement with #fn your Bind would continue to use "firstname" without needing to change.
However, if you updated your table and renamed the "firstname" column to "fn" this is no longer the case and you now have 2 choices:
Update all Bind() calls to use "fn" instead of "firstname" - this would require many changes if it occurs in many places.
Update your SELECT statement (or stored procedure) to alias the fn column as firstname (ie. SELECT [fn] as firstname, ... other columns ... FROM [user_info]) - this is advantageous since the change happens at the source and doesn't affect existing binding to "firstname," which means making a change in only one place.
I have a table which links to another table in the ASP.NET membership schema.
Problem is, all the PKs for the ASP.NET tables are uniqueidentifier so mine has to be too. When I add a SqlDatasource and call its Insert() method, I get the following error:
Cannot insert the value NULL into column 'DiscountCode', table 'CreamDb.dbo.CustomInfo1'; column does not allow nulls. INSERT fails.
The statement has been terminated.
The uniqueidentifier is also treated as an object (its data type), but there is no Guid data type. I had this problem before, but the schema was much simpler so I could fix it.
How can I go about fixing this? If I get rid of the data type part in the markup (so just leave the field/parameter name but not the data type stuff), I get another error so that is not possible.
Thanks
What do you mean by "there is no Guid data type"? What's wrong with System.Guid? Can't you just use Guid.NewGuid(), set the field appropriately, and do the insert?
EDIT: Just to give a bit more meat: attach an event handler to the Inserting event, and populate the field then, via the DbCommand returned by SqlDataSourceCommandEventArgs.Command. Or change the SQL used by the INSERT command to ask the database to populate the GUID field for you.
A popullar approach when dealing with references to the ASP.NET Membership Provider's data is, instead of keeping a proper foreign key to the GUIDs, instead store something like the LoweredUserName in your table. Then, use the Membership Provider's API to interact with the object you need. In some cases, you need an ObjectDataSource abstraction layer to accomplish CRUD scenarios.
Set the default value of the column in SQL Sever to "newid()".
Asp.net won't send the value, and the field will get a new guid.