Problems with editable DataGrid embedded in DataList

T

Todd

Hi,

I'm trying to get an editable master-detail style grid working.

I have a DataList of a set of orders. When you select an item, an
editable DataGrid is shown in-place with the order's details which can
be modified.

Unforunately clicking on the edit button does nothing.

Any ideas?

Source code below.

Thanks in advance,
Todd.

[the ASPX declaration]
<asp:DataList runat="server" id="OrderDataList"
OnSelectedIndexChanged="DisplayOrderDetails"
Font-Name="Verdana" Font-Size="10pt"
ItemStyle-BackColor="#eeeeee"
AlternatingItemStyle-BackColor="White"
CellPadding="8">
<ItemTemplate>
<b>Order #:</b> <%# DataBinder.Eval
(Container.DataItem, "RetailOrderID") %><br />
<b>Placed :</b> <%# ((DateTime)DataBinder.Eval
(Container.DataItem, "OrderDate")).ToLongDateString () %><br />
<b>Status :</b> <%# GetStatus
((int)DataBinder.Eval (Container.DataItem, "RetailOrderID")) %><br />
[<asp:LinkButton runat="server"
CommandName="Select" Font-Size="8pt" Text="View Order Details" />]
</ItemTemplate>
<SelectedItemTemplate>
<center><b>Order #:</b> <%# DataBinder.Eval
(Container.DataItem, "RetailOrderID") %></b></center><br />
<asp:DataGrid runat="server" id="dgOrderDetails"
DataSource=<%#
GetOrderDetails((int)DataBinder.Eval (Container.DataItem,
"RetailOrderID")) %>
AutoGenerateColumns="False" Font-Name="Verdana"
Font-Size="10pt" CellPadding="5"
AlternatingItemStyle-BackColor="#eeeeee"
ItemStyle-BackColor="White"
GridLines="None" ShowFooter="True"
DataKeyField="LineItemID"
OnEditCommand="dgOrderDetails_EditRow"
OnUpdateCommand="dgOrderDetails_UpdateRow"
OnCancelCommand="dgOrderDetails_CancelRow">
<Headerstyle BackColor="#99ccff"
Font-Size="10pt" Font-Bold="True" HorizontalAlign="Center" />
<Footerstyle BackColor="#99ccff"
Font-Size="10pt" Font-Bold="True" HorizontalAlign="Right" />
<Columns>
<asp:EditCommandColumn
ButtonType="PushButton" HeaderText="Edit" EditText="Edit"
UpdateText="Update" CancelText="Cancel" />
<asp:TemplateColumn HeaderText="Title"
ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<a
href='../TitleDetails.aspx?id=<%# DataBinder.Eval (Container.DataItem,
"TitleFormatID") %>'><%# GetTitle ((int)DataBinder.Eval
(Container.DataItem, "TitleFormatID")) %></a>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Condition"
ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<%# (bool)DataBinder.Eval
(Container.DataItem, "IsNew") ? "New" : "Used" %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn HeaderText="Quantity"
DataField="Quantity" ItemStyle-HorizontalAlign="Center" />
<asp:TemplateColumn HeaderText="Unit
Price" ItemStyle-HorizontalAlign="Right">
<ItemTemplate>
<%# string.Format ("{0:c}",
DataBinder.Eval (Container.DataItem, "UnitCost")) %>
</ItemTemplate>
<FooterTemplate>
$TODO
</FooterTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
<a href="#">View Tax Invoice</a>
</SelectedItemTemplate>
</asp:DataList>

[and the relevant code behind...]
public class YourAccount : System.Web.UI.Page {
protected DataList OrderDataList;
protected DataGrid dgOrderDetails;
protected DataSetHolder2 holder;
protected int orderBeingViewedID;

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack) {
BindData ();
}
}

private void BindData () {
MyDataLoader dl = (MyDataLoader)Session["DataLoader"];
holder = dl.LoadOrders ((int)Session["CustomerID"]);
OrderDataList.DataSource = holder["RetailOrder"];
OrderDataList.DataBind ();
}

protected DataView GetOrderDetails (int retailOrderID) {
orderBeingViewedID = retailOrderID;
return new DataView (holder["PartialOrderDetails"],
string.Format ("RetailOrderID={0}", retailOrderID), null,
DataViewRowState.CurrentRows);
}

protected string GetTitle (int titleFormatID) {
return string.Empty;
}

protected void DisplayOrderDetails (object sender, EventArgs
e) {
BindData ();
}

protected string GetStatus (int retailOrderID) {
return string.Empty;
}

protected void dgOrderDetails_EditRow (object sender,
DataGridCommandEventArgs e) {
DataGrid dg =
(DataGrid)OrderDataList.SelectedItem.Controls[1];
dg.EditItemIndex = e.Item.ItemIndex;
BindData ();
}

protected void dgOrderDetails_UpdateRow (object sender,
DataGridCommandEventArgs e) {
// TODO: update DB
DataGrid dg =
(DataGrid)OrderDataList.SelectedItem.Controls[1];
dg.EditItemIndex = -1;
BindData ();
}

protected void dgOrderDetails_CancelRow (object sender,
DataGridCommandEventArgs e) {
DataGrid dg =
(DataGrid)OrderDataList.SelectedItem.Controls[1];
dg.EditItemIndex = -1;
BindData ();
}

....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top