From: Harlan Messinger on
In ASP.NET 3.5: Suppose I have a ListView whose data source (using
LINQ-to-SQL) is set with an expression for a DataSource instead of a
control assigned to the ListView's DataSourceId field:

DataSource='<%#((IEnumerable<Bid>) Eval("Bids")).OrderBy(bid =>
bid.BidDateTime)%>'

This ListView is nested inside another one that shows information for an
Item in my Item table, and exposes Item.Bids, the related rows from the
Bid table. (This is for an auction.)

Since I'm not using a LinqDataSource for this ListView, I don't have any
built-in functionality for insertion, updating, deletion, and I can't
seem to find out just how to do that. Any guidance, please?
From: Harlan Messinger on
Harlan Messinger wrote:
> In ASP.NET 3.5: Suppose I have a ListView whose data source (using
> LINQ-to-SQL) is set with an expression for a DataSource instead of a
> control assigned to the ListView's DataSourceId field:
>
> DataSource='<%#((IEnumerable<Bid>) Eval("Bids")).OrderBy(bid =>
> bid.BidDateTime)%>'
>
> This ListView is nested inside another one that shows information for an
> Item in my Item table, and exposes Item.Bids, the related rows from the
> Bid table. (This is for an auction.)
>
> Since I'm not using a LinqDataSource for this ListView, I don't have any
> built-in functionality for insertion, updating, deletion, and I can't
> seem to find out just how to do that. Any guidance, please?

I've tried this, where a user has entered a bid:

ListView lv = (ListView)sender;
decimal bidPrice =
decimal.Parse(((TextBox)lv.InsertItem.FindControl("txtBidCount")).Text);

//Insert validation code here.

Bid bid = new Bid();
bid.ItemId = ???;
bid.ParticipantId = Session["userParticipantId"];
bid.BidPrice = bidPrice;
bid.BidDateTime = DateTime.Now;
bid.IsOnlineBid = true;

AuctionData data = new AuctionData();
data.Bids.InsertOnSubmit(bid);
data.SubmitChanges();


But I don't know what my source should be for the itemId with which this
Bid should be associated. It's the same as the ItemId of the current
item in the outer ListView, but I don't know how to get at that from
within the inner ListView. I thought it might have something to do with
inspecting lv.DataSource, but that actually seems to be null at this
point, according to the Locals window.
From: Mr. Arnold on
Harlan Messinger wrote:
> In ASP.NET 3.5: Suppose I have a ListView whose data source (using
> LINQ-to-SQL) is set with an expression for a DataSource instead of a
> control assigned to the ListView's DataSourceId field:
>
> DataSource='<%#((IEnumerable<Bid>) Eval("Bids")).OrderBy(bid =>
> bid.BidDateTime)%>'
>
> This ListView is nested inside another one that shows information for an
> Item in my Item table, and exposes Item.Bids, the related rows from the
> Bid table. (This is for an auction.)
>
> Since I'm not using a LinqDataSource for this ListView, I don't have any
> built-in functionality for insertion, updating, deletion, and I can't
> seem to find out just how to do that. Any guidance, please?


I guess you're going to need the insert, update and delete templates,
tying them to a method on the codebehind file. And depending on what
event you're trying to do, do with code manually.


This just off the top of my head, but it would be something like this.

If (e.command == "Update")
{

}

If e.command == "Insert")
{

}


There is nothing stopping you from using Linq-2-SQL in this manner.
From: Harlan Messinger on
Mr. Arnold wrote:
> Harlan Messinger wrote:
>> In ASP.NET 3.5: Suppose I have a ListView whose data source (using
>> LINQ-to-SQL) is set with an expression for a DataSource instead of a
>> control assigned to the ListView's DataSourceId field:
>>
>> DataSource='<%#((IEnumerable<Bid>) Eval("Bids")).OrderBy(bid =>
>> bid.BidDateTime)%>'
>>
>> This ListView is nested inside another one that shows information for
>> an Item in my Item table, and exposes Item.Bids, the related rows from
>> the Bid table. (This is for an auction.)
>>
>> Since I'm not using a LinqDataSource for this ListView, I don't have
>> any built-in functionality for insertion, updating, deletion, and I
>> can't seem to find out just how to do that. Any guidance, please?
>
>
> I guess you're going to need the insert, update and delete templates,
> tying them to a method on the codebehind file. And depending on what
> event you're trying to do, do with code manually.
>
>
> This just off the top of my head, but it would be something like this.
>
> If (e.command == "Update")
> {
>
> }
>
> If e.command == "Insert")
> {
>
> }
>
>
> There is nothing stopping you from using Linq-2-SQL in this manner.

Right, I'm beyond that point, which is happening automatically. My
follow-up e-mail to myself goes into more detail. The OnItemInserting
handler is being called, and I think I have most of its contents squared
away but I've got one unsolved question, and the last few lines are
untested.
From: Mr. Arnold on
Harlan Messinger wrote:
> Harlan Messinger wrote:
>> In ASP.NET 3.5: Suppose I have a ListView whose data source (using
>> LINQ-to-SQL) is set with an expression for a DataSource instead of a
>> control assigned to the ListView's DataSourceId field:
>>
>> DataSource='<%#((IEnumerable<Bid>) Eval("Bids")).OrderBy(bid =>
>> bid.BidDateTime)%>'
>>
>> This ListView is nested inside another one that shows information for
>> an Item in my Item table, and exposes Item.Bids, the related rows from
>> the Bid table. (This is for an auction.)
>>
>> Since I'm not using a LinqDataSource for this ListView, I don't have
>> any built-in functionality for insertion, updating, deletion, and I
>> can't seem to find out just how to do that. Any guidance, please?
>
> I've tried this, where a user has entered a bid:
>
> ListView lv = (ListView)sender;
> decimal bidPrice =
> decimal.Parse(((TextBox)lv.InsertItem.FindControl("txtBidCount")).Text);
>
> //Insert validation code here.
>
> Bid bid = new Bid();
> bid.ItemId = ???;
> bid.ParticipantId = Session["userParticipantId"];
> bid.BidPrice = bidPrice;
> bid.BidDateTime = DateTime.Now;
> bid.IsOnlineBid = true;
>
> AuctionData data = new AuctionData();
> data.Bids.InsertOnSubmit(bid);
> data.SubmitChanges();
>
>
> But I don't know what my source should be for the itemId with which this
> Bid should be associated. It's the same as the ItemId of the current
> item in the outer ListView, but I don't know how to get at that from
> within the inner ListView. I thought it might have something to do with
> inspecting lv.DataSource, but that actually seems to be null at this
> point, according to the Locals window.

Wouldn't just use a asp:HiddenField that's global to the page? The
outter Listview would save itemid to the HF, and then Listview inner
would get the value from the HF.

And I don't see how you're going to use a datasource that belongs to
another control.

The ObjectContext is there for the Linq-2-SQL from a codebehind file
standpoint, which you may have to go to the codebehind file and manually
do the CURD for the other control.