Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 12th, 2007, 01:35 PM
saf saf is offline
Authorized User
 
Join Date: Nov 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default Master/Detail read only data

Hi Imar -
I've searched and searched on this one and have come up with nothing so thought I'd come to the expert...

I want to create a master/detail listing on the same page. I do not need any update/insert/select capability. I just want to display categories from my database with the selected products next to it. Everything is read only so I'll never have a category selected to bind to. I want the category row to display only when it changes, like this:

Categoryi product1
             product 2
             product 3
Category2 product 1
             product 2 etc....

The only thing I can think of is to pull all the data in one query (which results in a complicated query...) group the data and omit the aggregate column since I don't need it - I know this is NOT the best way....

THANKS!
saf

 
Old January 12th, 2007, 06:43 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Depending on how you want to do it, you have a few options.

One is to use a nested Repeater, where you add a Repeater to the <ItemTemplate> of another.

Searching Google for asp.net nested repeater should bring up some useful results....

My book ASP.NET 2 Instant Results has a chapter that uses nested Repeaters to display report type data like this....

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: Girls by Tricky (Track 4 from the album: Blowback) What's This?
 
Old January 17th, 2007, 02:33 PM
saf saf is offline
Authorized User
 
Join Date: Nov 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar

I've got everything to display using the nested repeater with a Gridview but I'm stuck on this.... I need to add a textbox to the repeater where you can enter a quantity. When the value changes I want to calculate the subtotal with value of quantity textbox * the bound Price value pulled from my datasource. I'm posting my code so it makes more sense. I'm not editing any table data at this point, I just want to be able to show user subtotal value when they enter a quantity...

See this line - <td> <%#FormatNumber(Container.DataItem("Price") * 4)%> Instead of *4 I want to pull the value of the Quantity textbox when in changes to perform this calculation - Please Help.
(I tried client side Javascript?? but can't get it to work...)

 <asp:GridView ID="OrderFormGridView" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="LunchDateId" DataSourceID="LunchDateDataSource" ForeColor="#333333"GridLines="Horizontal" AlternatingRowStyle-BorderStyle = "Groove" AlternatingRowStyle-BorderWidth = "2">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
   <Columns>
  <asp:TemplateField SortExpression="LunchDate">
 <ItemTemplate>
 <asp:Label ID="Label1" runat="server" width="150" Text='<%# Eval("LunchDate", "{0:d}") %>'></asp:Label><br />
 <asp:Label ID="Label2" runat="server" Text='<%# Eval("CategoryName") %>'></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Font-Bold="True" Font-Names="Arial" Font-Size="Medium" HorizontalAlign="Center" Width = "150px" />
                            <HeaderStyle Font-Bold="True" Font-Names="Arial" Font-Size="Medium" HorizontalAlign="Center"
                                Width="100px" Wrap="False" />
                        </asp:TemplateField>
<asp:TemplateField HeaderText="Meal Item" >
 <ItemTemplate>
  <asp:Repeater Id= "Repeater1" EnableViewState = "true" runat="server" DataSource='<%# GetCategoryItemsInCategory(CType(Eval("CategoryId" ), Integer)) %>'>
  <ItemTemplate>
 <table cellspacing = "2" width = "100%">
    <tr>
 <td class="CategoryItemsPropertyValue" width="400" align="right">
                <asp:Label ID="CategoryItemNameLabel" runat="server"
                    Text='<%#Container.DataItem("CategoryItemName")%>' />

            </td>
             <td class="CategoryItemsPropertyValue" width="45" align="left">
                <asp:Label ID="PriceLabel" runat="server"
                 Text='<%# DataBinder.Eval(Container.DataItem,"Price", "${0:F2}") %>'/>
       <td >
  <asp:Textbox runat="Server" ID="txtQuantity" tabindex = "3" width = "25" ToolTip="Enter Quantity" />
            </td>
  <td> <%#FormatNumber(Container.DataItem("Price") * 4)%>

             </tr>
             </table>
             </ItemTemplate>
             </asp:Repeater>
             </ItemTemplate>
                            <ItemStyle Font-Bold="False" Font-Names="Arial" Font-Size="Small"/>
                            <HeaderStyle width = "400px" HorizontalAlign="Right" font-Bold="True" Font-Names="Arial" Font-Size="Medium" />
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                            </EditItemTemplate>
                        </asp:TemplateField>


                </Columns>
                    <RowStyle BackColor="#EFF3FB" />
                    <EditRowStyle BackColor="#2461BF" />
                    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <AlternatingRowStyle BackColor="White" BorderStyle="Groove" BorderWidth="2px" />
                </asp:GridView>

    <asp:ObjectDataSource ID="LunchDateDataSource" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetLunchDatesBySchoolId"
        TypeName="LunchDateBLL" UpdateMethod="UpdateLunchDate">

        <SelectParameters>
            <asp:SessionParameter Name="schoolId" SessionField="SchoolID" Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>



 
Old January 17th, 2007, 02:59 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
quote:I tried client side Javascript?? but can't get it to work...
Do you want to use JavaScript? If so, can you define "but can't get it to work"? Do you get an error?

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old January 17th, 2007, 05:56 PM
saf saf is offline
Authorized User
 
Join Date: Nov 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK - Here is the error:
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Quantity'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Quantity'.

Source Error:


Line 65: <asp:Textbox runat="Server" ID="txtQuantity" tabindex = "3" width = "25" ToolTip="Enter Quantity" />
Line 66: </td>
Line 67: <td> <%#FormatNumber(Container.DataItem("Price") * Eval("Quantity"))%>
Line 68:
Line 69: </tr>



Here is what I tried.....I just want to get the value of the Quantity TextBox....I can do the calculation here (I thinK?)
<td> <%#FormatNumber(Container.DataItem("Price") * Eval("Quantity"))%>

On RowCreated:
  Dim tbquantity As TextBox = e.Row.FindControl("Quantity")
        If Not tbquantity Is Nothing Then
            tbquantity.Attributes.Add("onBlur", "getQuantityValue(" & tbquantity.ClientID & ")")
        End If

In aspx page:
Function getQuantityValue(curQuantity){
var Qty = document.getElementById(curQuantity).Value;
}

If it looks familiar I took it from one of your other posts.
Where am I going wrong? Problem seems to be quantity is not bound to anything in the repeater but there must be a simple way to get the value of the textbox when it changes???

THANKS!

 
Old January 18th, 2007, 03:19 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

The DataBinding error is because you don't have a Quantity column in your data source; you calculate it on the fly, so that makes sense.

However, I think there are some other issues:
Quote:
quote:Function getQuantityValue(curQuantity){
var Qty = document.getElementById(curQuantity).Value;
}
function is with a lower case f in JavaScript, and so is value.:
Quote:
quote:function getQuantityValue(curQuantity)
{
  var Qty = document.getElementById(curQuantity).value;
}
But there's more; you just define var Qty but do nothing wit it, like return it to the calling code.
Quote:
quote:function getQuantityValue(curQuantity)
{
  // either do this
  return document.getElementById(curQuantity).value;

 // or use it in some other way:
  var Qty = document.getElementById(curQuantity).value;
  document.getElementById(someOtherFiel).value = Qty;
}
In your case, I think you want to talk to two different fields in JavaScript: the quantity and the total. So try the following:

1. In RowCreated, pass the client IDs of both text boxes to the onblur event handler

2. Change the JavaScript function so it accepts two values

3. Get the value from the first field, do the calculation and update the second field, as in my last example.

You may need to extend this idea to three text boxes: the price, the quantity and the total, although the concept remains the same.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old January 18th, 2007, 11:23 AM
saf saf is offline
Authorized User
 
Join Date: Nov 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Imar - I'm trying...
I have this:
 Protected Sub OrderFormGridView_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles OrderFormGridView.RowCreated
        Dim tbquantity As TextBox = e.Row.FindControl("Quantity")
        Dim tbsubtotal As TextBox = e.Row.FindControl("SubTotal")
        If Not tbquantity Is Nothing Then
            tbquantity.Attributes.Add("onBlur", "calcSubTotal(" & tbquantity.ClientID & "," & tbsubtotal.ClientID & ")")
        End If
    End Sub

problem is onblur attribute is never being set because its never getting in that if..endif code block. So FindControl is not finding anything...I'm so lost.. here is my ItemTemplate code (its in a nested repeater inside a gridview...

 <ItemTemplate>
                                <table cellspacing = "2" width = "100%">
                                <tr>
            <td class="CategoryItemsPropertyValue" width="400" align="right">
                <asp:Label ID="CategoryItemNameLabel" runat="server"
                    Text='<%#Container.DataItem("CategoryItemName")%>' />

            </td>
             <td class="CategoryItemsPropertyValue" width="45" align="left">
                <asp:Label ID="PriceLabel" runat="server"
                 Text='<%# DataBinder.Eval(Container.DataItem,"Price", "${0:F2}") %>'/>
          </td>

                <td >
                <asp:Textbox runat="Server" ID="txtQuantity" tabindex = "3" width = "25" ToolTip="Enter Quantity" />
            </td>
             <td>
             <asp:Textbox runat="Server" ID="SubTotal" width = "25" BorderStyle="None" />

               </td>
             </tr>
             </table>
             </ItemTemplate>

Is javascript the best way to go with this? If so, do I need to create an array of the clientside ids for all the quantity textboxes first (I've seen some posts on this with checkbox's)

THANK YOU SO MUCH, i'm really struggling on this one... -

 
Old January 18th, 2007, 11:27 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I can only guess as you haven't posted the full source, but I think you should first find the Repeater in the GridView using e.Row.FindControl and then find the textbox in the Repeater....

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old January 19th, 2007, 02:14 PM
saf saf is offline
Authorized User
 
Join Date: Nov 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Imar
Last question...
I'm really close. My function is working -
function calcSubTotal(oPrice, oQty, oSubTotal){
    var qty = document.getElementById(oQty).value;
     alert(qty);
    alert(oPrice);
    var SubTotal = qty*oPrice;
    alert(SubTotal);
     }
I've got all my variables set - can you point me in the right direction to get the SubTotal to display on my page...

Here is the Itemdatabound event that passes the variables to the above function
 - going on 3 days now with this one...

 Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
        Dim pri As String = e.Item.DataItem("Price")
        Dim tb2 As TextBox = e.Item.FindControl("Quantity")
        Dim tb3 As TextBox = e.Item.FindControl("SubTotal")
        If Not tb2 Is Nothing Then
            tb2.Attributes.Add("onBlur", "calcSubTotal( '" & pri & " ','" & tb2.ClientID & "','" & tb3.ClientID & "')")
        End If

    End Sub

As always, thank you thank you...
saf




 
Old January 19th, 2007, 02:33 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You can use document.getElementById() in JavaScript to get a reference to the Total box and then set its value, similar to how you read it for the quantity:
Code:
function calcSubTotal(oPrice, oQty, oSubTotal)
{
  var qty = document.getElementById(oQty).value;
  alert(qty);
  alert(oPrice);
  var SubTotal = qty*oPrice;
  alert(SubTotal);
  document.getElementById(oSubTotal).value - SubTotal;
}
Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
master-detail hhpatek ADO.NET 0 April 3rd, 2008 02:53 PM
Master Detail prasanta2expert Access VBA 1 October 1st, 2007 06:37 AM
Master/Detail Data Presentation in GridView AbrarNazeer ASP.NET 2.0 Professional 0 June 22nd, 2006 12:59 AM
master/detail beeyule Dreamweaver (all versions) 1 January 18th, 2005 02:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.