|
 |
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
 |
|
|

March 29th, 2010, 05:47 AM
|
Registered User
|
|
Join Date: Mar 2010
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How do I pre-populate a frontend control using asp.net c#?
Hi,
I have the below three events (base of question) mapped to my asp.net listview control. Basically my listview should show multiple rows of data with each row showing its own rating control value.
Within the ItemTemplate of my listview control I have the below rating control (more info can be found at: http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=410). The code requires an "ItemId" (UserId value (GUID type) supplied from my attached BindData method - LINQ query) value to display it's data.
Code:
<isp:ContentRating
ID="ContentRating1"
runat='server'
LegendText="rates: {0} avg: {1}"
ItemId='<%# Eval("UserId") %>' />
Unfortunately I'm receiving an error on the line "lvTrustAccounts.DataBind();" within my BindData method shown below as the "UserId" value within the ItemId attribute of my ContentRating control seems to be null (or not created yet), thus data binding is not possible. I think this is due to the fact that my ItemDataBound event is not getting hit to populate this attribute within my control. How can I alter the flow of my events to populate my rating control array with the rating values (rating1, rating2 etc) attached to each valid UserId?
Any help appreciated.
Code:
protected void Page_PreRender(object sender, EventArgs e)
{
BindData();
}
private void BindData()
{
TradeSelectorDataContext db = new TradeSelectorDataContext();
var query =
(
from tt in db.tblTraders
join ttcl in db.tblCityLookups on tt.city_id equals ttcl.city_id
join lctt in db.tblCountryLookups on tt.country_id equals lctt.country_id
join tcl in db.tblCountyLookups on tt.county_id equals tcl.county_id
join twal in db.tblTraderWorkingAreaLookups on tt.trader_working_area_id equals twal.trader_working_area_id
join ttrade in db.tblTraderTrades on tt.UserId equals ttrade.UserId
join trade in db.tblTrades on ttrade.trade_id equals trade.trade_id
join ttt in db.tblTradeTradeTypes on trade.trade_id equals ttt.trade_id
join tradet in db.tblTradeTypes on ttrade.trade_type_id equals tradet.trade_type_id
join cj in db.tblCustomerJobs on trade.trade_id equals cj.trade_id
join tr in db.tblTraderRatings on tt.UserId equals tr.UserId
//join tc in db.tblCustomers on cj.UserId equals tc.UserId
orderby tt.trader_firstname ascending
select new
{
tt.UserId
,
tt.trader_title
,
tt.trader_firstname
,
tt.trader_surname
,
tt.trader_phone1
,
tt.trader_phone2
,
tt.trader_working_area_id
,
tt.trader_overall_rating
,
trader_working_area_name = twal.trader_working_area_name.Substring(0, twal.trader_working_area_name.IndexOf('(')).Trim()
,
trader_working_area_postcodes = twal.trader_working_area_name.Substring(twal.trader_working_area_name.IndexOf('(') + 1, twal.trader_working_area_name.LastIndexOf(')') - twal.trader_working_area_name.IndexOf('(') - 1).Trim()
,
trade_type_name = tradet.trade_type_name == null ? "" : tradet.trade_type_name
,
trade.trade_name
,
ttrade.trade_type_id
,
ttrade.trade_id
,
tr.Rating01
,
tr.Rating02
,
tr.Rating03
,
tr.Rating04
,
tr.Rating05
}
).Distinct();
lvTrustAccounts.DataSource = query;
lvTrustAccounts.DataBind();
}
protected void lvTrustAccounts_ItemDataBound(object sender, ListViewItemEventArgs e)
{
Object dataRecord = ((ListViewDataItem)e.Item).DataItem; // Get the dataitem and place it into dataRecord
Type anonType = dataRecord.GetType(); // get the anonymous type
// Get user id and rating values using reflection
Guid userid = (Guid)anonType.GetProperty("UserId").GetValue(dataRecord, null);
int rating1 = (int)anonType.GetProperty("Rating01").GetValue(dataRecord, null);
int rating2 = (int)anonType.GetProperty("Rating02").GetValue(dataRecord, null);
int rating3 = (int)anonType.GetProperty("Rating03").GetValue(dataRecord, null);
int rating4 = (int)anonType.GetProperty("Rating04").GetValue(dataRecord, null);
int rating5 = (int)anonType.GetProperty("Rating05").GetValue(dataRecord, null);
// Put rating values in array
int[] rateValues = new int[]
{
rating1, rating2, rating3, rating4, rating5
};
// Get a reference to the rating control, and set and bind the data
Spaanjaars.Toolkit.ContentRating ratingControl = (Spaanjaars.Toolkit.ContentRating)e.Item.FindControl("ContentRating1");
//Below is bound within the frontend control
//ratingControl.ItemId = userid;
ratingControl.DataSource = rateValues;
ratingControl.DataBind();
}
Last edited by martinspalding; March 29th, 2010 at 12:38 PM..
Reason: update
|

March 29th, 2010, 12:42 PM
|
 |
Wrox Author
Points: 72,055, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
|
|
Hi there,
Why are you binding in Page_PreRender? That's too late for most data bound scenarios. have you tried binding in Page_Load?
Cheers,
Imar
|

March 30th, 2010, 05:16 AM
|
Registered User
|
|
Join Date: Mar 2010
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar,
I get the same error from Page_Load, i.e. my ItemDataBound event is not firing before the error? I know my BindData query returns one row as when I comment out your ContentRating control within my .aspx page and all references to "ratingControl" within my .cs page, the page loads fine showing my one row of data. For some reason I can't bind your ItemId attribute to my backend UserId value (this is of data type uniqueidentifier/guid by the way).
Thanks.
|

March 30th, 2010, 05:25 AM
|
Registered User
|
|
Join Date: Mar 2010
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I can also see from debug, on the below "query" reference, that all the correct data values are being returned, even the correct UserId guid value...
lvTrustAccounts.DataSource = query;
|

March 30th, 2010, 02:24 PM
|
 |
Wrox Author
Points: 72,055, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
|
|
Are you sure lvTrustAccounts_ItemDataBound is hooked up correctly? Can you show us the rest of your code?
Imar
|

March 31st, 2010, 06:10 AM
|
Registered User
|
|
Join Date: Mar 2010
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
default.aspx page
Code:
<%@ Page Title="" Language="C#" MasterPageFile="~/SingleColumn.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="Spaanjaars.Toolkit" Namespace="Spaanjaars.Toolkit" TagPrefix="isp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
<!--********************************************************-->
<!--********Pulls in the contextKey needed for the dropdown filter********-->
<!--********************************************************-->
<script type="text/javascript">
function pageLoad(sender, args) {
var autoComplete = $find('autoComplete');
autoComplete.add_populating(function() {
// use the filter as the context key
autoComplete.set_contextKey($get('<%= this.ddlFilter.ClientID %>').value);
});
autoComplete.add_itemSelected(function() {
// force the panel to refresh
__doPostBack('<%= this.TrustAccountsUpdatePanel.ClientID %>', '');
});
}
</script>
<div class="validationAsterix">
* Indicates a required field.
</div>
<div>
<asp:Updatepanel ID="TrustAccountsUpdatePanel" runat="server" UpdateMode="Conditional">
<contentTemplate>
<div id="dlg" class="panelTrustAccounts" style="width:915px">
<div class="headerTrustAccounts" style="cursor:default">
<div class="outerTrustAccounts">
<div class="innerTrustAccounts">
<div class="contentTrustAccounts">
<h2>Trade Selector</h2>
<%--****************************************************************--%>
<%--*************ListView Filter dropdown and textbox with autocomplete**********--%>
<%--****************************************************************--%>
<div class="filterTrustAccounts">
<asp:DropDownList ID="ddlFilter" runat="server">
<asp:ListItem Text="Trader First Name" Value="trader_firstname" />
<asp:ListItem Text="Trader Surname" Value="trader_surname" />
<asp:ListItem Text="Trade" Value="trade_name" />
<asp:ListItem Text="Area" Value="trader_working_area_name" />
</asp:DropDownList>
<asp:TextBox Width="300px" ID="txtFilter" runat="server" autocomplete="off" OnTextChanged="FilterChanged" />
<asp:ImageButton ID="btnClear" runat="server" AlternateText="Remove Filter" ImageUrl="~/App_Themes/images/TrustAccountsUI/clear.gif" OnClick="ClearFilter" Height="16px" Width="16px" />
<ajaxToolkit:AutoCompleteExtender
ID="autoComplete"
BehaviorID="autoComplete"
runat="server"
EnableCaching="true"
TargetControlID="txtFilter"
ServiceMethod="GetCompletionList"
CompletionSetCount="10"
UseContextKey="true"
ContextKey="test"
MinimumPrefixLength="2"
CompletionInterval="1000"
CompletionListCssClass="autocomplete_list"
CompletionListItemCssClass="autocomplete_listItem"
CompletionListHighlightedItemCssClass="autocomplete_highlighted_listitem">
<Animations>
<OnShow>
<Sequence>
<%-- Make the completion list transparent and then show it --%>
<OpacityAction Opacity="0" />
<HideAction Visible="true" />
<%--Cache the original size of the completion list the first time
the animation is played and then set it to zero --%>
<ScriptAction Script="
// Cache the size and setup the initial size
var behavior = $find('autoComplete');
if (!behavior._height) {
var target = behavior.get_completionList();
behavior._height = target.offsetHeight - 2;
target.style.height = '0px';
}" />
<%-- Expand from 0px to the appropriate size while fading in --%>
<Parallel Duration=".4">
<FadeIn />
<Length PropertyKey="height" StartValue="0" EndValueScript="$find('autoComplete')._height" />
</Parallel>
</Sequence>
</OnShow>
<OnHide>
<%-- Collapse down to 0px and fade out --%>
<Parallel Duration=".4">
<FadeOut />
<Length PropertyKey="height" StartValueScript="$find('autoComplete')._height" EndValue="0" />
</Parallel>
</OnHide>
</Animations>
</ajaxToolkit:AutoCompleteExtender>
</div>
<%--*****************************************************************************--%>
<%--************************************END**************************************--%>
<%--*****************************************************************************--%>
</div>
</div>
</div>
</div>
<div class="bodyTrustAccounts">
<div class="outerTrustAccounts">
<div class="innerTrustAccounts">
<div class="contentTrustAccounts">
<%--************************************************************************--%>
<%--*************************ListView with DataSource****************************--%>
<%--************************************************************************--%>
<asp:LinqDataSource
ID="TrustsDataSource"
runat="server"
ContextTypeName="TradeSelectorDataContext"
TableName="tblCustomers" />
<asp:ListView
ID="lvTrustAccounts"
runat="server"
DataKeyNames="UserId"
DataMember="DefaultView"
OnItemDataBound="lvTrustAccounts_ItemDataBound"
OnPreRender="Page_PreRender">
<LayoutTemplate>
<table id="TrustAccounts" runat="server" class="gridTrustAccounts" cellspacing="0" border="0">
<tr>
<th><asp:LinkButton ID="btnSortTraderContact" runat="server" Text="Trader Contact Details" CommandName="Sort" CommandArgument="trader_firstname" Width="190px" /></th>
<th><asp:LinkButton ID="btnSortTraderDetails" runat="server" Text="Trader Details" CommandName="Sort" CommandArgument="trade_id" Width="110px" /></th>
<th><asp:LinkButton ID="btnSortTraderRating" runat="server" Text="Trader Overall Rating" CommandName="Sort" CommandArgument="trader_overall_rating" Width="150px" /></th>
</tr>
<tr id="itemPlaceholder" runat="server" />
<tr class="pagerTrustAccounts">
<td colspan="9">
<div class="container">
<%--********************************************************************--%>
<%--********************ListView Pager with Page Slide Control ********************--%>
<%--********************************************************************--%>
<asp:DataPager ID="pagerTrustAccounts" runat="server" PageSize="10">
<Fields>
<asp:TemplatePagerField OnPagerCommand="PagerCommand">
<PagerTemplate>
<div class="commandTrustAccounts">
<asp:ImageButton ID="btnFirst" runat="server" CommandName="First" ImageUrl="~/App_Themes/images/TrustAccountsUI/first.gif" AlternateText="First Page" ToolTip="First Page" />
<asp:ImageButton ID="btnPrevious" runat="server" CommandName="Previous" ImageUrl="~/App_Themes/images/TrustAccountsUI/prev.gif" AlternateText="Previous Page" ToolTip="Previous Page" />
</div>
<div class="commandTrustAccounts">
<asp:TextBox
ID="txtSlider" runat="server"
Text=
'<%#
Container.TotalRowCount > 0
? Math.Ceiling(((double)(Container.StartRowIndex + Container.MaximumRows) / Container.MaximumRows))
: 0
%>'
AutoPostBack="true" OnTextChanged="CurrentPageChanged"
style="visibility:hidden" />
<ajaxToolkit:SliderExtender
ID="slider" BehaviorID="slider" runat="server"
TargetControlID="txtSlider"
Orientation="Horizontal"
Minimum="1"
Maximum='<%# Math.Ceiling((double)Container.TotalRowCount / Container.MaximumRows) %>'
TooltipText='<%# "Page {0} of " + Math.Ceiling ((double)Container.TotalRowCount / Container.MaximumRows).ToString() + " (" + Container.TotalRowCount + " items)" %>'/>
</div>
<div class="commandTrustAccounts">
<asp:ImageButton ID="btnNext" runat="server" CommandName="Next" ImageUrl="~/App_Themes/images/TrustAccountsUI/next.gif" AlternateText="Next Page" ToolTip="Next Page" />
<asp:ImageButton ID="btnLast" runat="server" CommandName="Last" ImageUrl="~/App_Themes/images/TrustAccountsUI/last.gif" AlternateText="Last Page" ToolTip="Last Page" />
</div>
<div class="info">
Page
<b>
<%# Container.TotalRowCount > 0 ? Math.Ceiling(((double)(Container.StartRowIndex + Container.MaximumRows) / Container.MaximumRows)) : 0%>
</b>
of
<b>
<%# Math.Ceiling((double)Container.TotalRowCount / Container.MaximumRows)%>
</b>
(<%# Container.TotalRowCount%> items)
</div>
</PagerTemplate>
</asp:TemplatePagerField>
</Fields>
</asp:DataPager>
<%--**************************************************************--%>
<%--*****************************END******************************--%>
<%--**************************************************************--%>
</div>
</td>
</tr>
</table>
</LayoutTemplate>
<EmptyDataTemplate>
<table id="Table1" runat="server" style="">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<%--The line below allows for the itemtemplate (odd numbers) to also accommodate for the alternateitemtemplate (even numbers) as these two template are, in my case, a duplicate of each other. The style classes to use for each are specified after the "?".--%>
<tr class='<%# (Container.DataItemIndex % 2 == 0)?"row":"altrow" %>' id="row" runat="server" style="height:108px;">
<td>
<asp:ImageButton AlternateText="Trader" ID="ImageButtonTradesman" runat="server" ImageUrl="~/App_Themes/images/trademan10.png" />
<b>
<%# Eval("trader_title") %>. <%# Eval("trader_firstname") %> <%# Eval("trader_surname")%>
</b>
<br />
<asp:ImageButton AlternateText="Traders Phone Number" ID="ImageButtonPhone" runat="server" ImageUrl="~/App_Themes/images/phone15.jpg" />
<b>
<font color="green">
<%# Eval("trader_phone1") %>
</font>
</b>
<br />
<asp:ImageButton AlternateText="Traders Mobile Number" ID="ImageButtonMobile" runat="server" ImageUrl="~/App_Themes/images/mobile15.jpg" />
<b>
<font color="green">
<%# Eval("trader_phone2") %>
</font>
</b>
<%--<br />
<asp:ImageButton AlternateText="Email Trader" ID="ImageButtonEmail" runat="server" ImageUrl="~/App_Themes/images/email15.jpg" />
<a href="mailto:<%#Eval("customer_email")%>"><%#Eval("trader_email")%></a>--%>
</td>
<td>
<b>
<%# Eval("trade_type_name")%> <%# Eval("trade_name") %>
</b>
within
<b>
<%# Eval("trader_working_area_name")%>
</b>
<ajaxToolkit:HoverMenuExtender
ID="HoverMenuExtenderArea"
runat="server"
TargetControlID="ImageButtonArea"
PopupControlID="PanelPopUpArea"
PopupPosition="Right"
OffsetX="5"
PopDelay="25"
HoverCssClass="popupHover">
</ajaxToolkit:HoverMenuExtender>
<asp:Panel
ID="PanelPopUpArea"
runat="server"
Width="165px"
CssClass="popupMenu">
<asp:Label ID="LabelNotesArea" runat="server" Text='<%# Eval("trader_working_area_postcodes") %>'></asp:Label>
</asp:Panel>
<asp:ImageButton ID="ImageButtonArea" runat="server" ImageUrl="~/App_Themes/images/info.png" />
</td>
<td>
<isp:ContentRating
ID="ContentRating1"
runat='server'
LegendText="rates: {0} avg: {1}" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<%--*****************************************************************************--%>
<%--*****************************End List View***********************************--%>
<%--*****************************************************************************--%>
</div>
</div>
</div>
</div>
<div class="footerTrustAccounts">
<div class="outerTrustAccounts">
<div class="innerTrustAccounts">
<div class="contentTrustAccounts"></div>
</div>
</div>
</div>
</div>
</contentTemplate>
</asp:Updatepanel>
</div>
</asp:Content>
Last edited by martinspalding; March 31st, 2010 at 06:14 AM..
|

March 31st, 2010, 06:15 AM
|
Registered User
|
|
Join Date: Mar 2010
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
default.cs page
Code:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
//using AjaxControlToolkit;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Linq.Mapping;
using System.Linq.Expressions;
using System.Reflection;
using System.Data.SqlClient;
using System.Globalization;
public partial class _Default : System.Web.UI.Page
{
public string thisConnectionString = ConfigurationManager.ConnectionStrings["TradeSelectorConnectionString"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (Request.IsAuthenticated)
{
FormsAuthentication.SetAuthCookie(HttpContext.Current.User.Identity.Name, false);
Response.Redirect("Customers.aspx");
}
BindData();
}
protected void PagerCommand(object sender, DataPagerCommandEventArgs e)
{
DataPager pager = e.Item.Pager;
int newStartRowIndex;
switch (e.CommandName)
{
case "Next":
newStartRowIndex = pager.StartRowIndex + pager.MaximumRows > pager.TotalRowCount ? pager.StartRowIndex : pager.StartRowIndex + pager.MaximumRows;
break;
case "Previous":
newStartRowIndex = pager.StartRowIndex - pager.MaximumRows < 0 ? pager.StartRowIndex : pager.StartRowIndex - pager.MaximumRows;
break;
case "Last":
newStartRowIndex = (pager.TotalRowCount / pager.MaximumRows) * pager.MaximumRows;
break;
case "First":
default:
newStartRowIndex = 0;
break;
}
e.NewMaximumRows = e.Item.Pager.MaximumRows;
e.NewStartRowIndex = newStartRowIndex;
}
protected void CurrentPageChanged(object sender, EventArgs e)
{
TextBox txtCurrentPage = sender as TextBox;
DataPager pager = this.lvTrustAccounts.FindControl("pagerTrustAccounts") as DataPager;
int startRowIndex = (int.Parse(txtCurrentPage.Text) - 1) * pager.MaximumRows;
pager.SetPageProperties(startRowIndex, pager.MaximumRows, true);
}
protected void FilterChanged(object sender, EventArgs e)
{
// rebind the grid
this.lvTrustAccounts.DataBind();
}
protected void ClearFilter(object sender, ImageClickEventArgs e)
{
// remove the filter and rebind the grid
this.txtFilter.Text = string.Empty;
this.lvTrustAccounts.DataBind();
}
protected void Page_PreRender(object sender, EventArgs e)
{
//BindData();
}
private void BindData()
{
TradeSelectorDataContext db = new TradeSelectorDataContext();
var query =
(
from tt in db.tblTraders
join ttcl in db.tblCityLookups on tt.city_id equals ttcl.city_id
join lctt in db.tblCountryLookups on tt.country_id equals lctt.country_id
join tcl in db.tblCountyLookups on tt.county_id equals tcl.county_id
join twal in db.tblTraderWorkingAreaLookups on tt.trader_working_area_id equals twal.trader_working_area_id
join ttrade in db.tblTraderTrades on tt.UserId equals ttrade.UserId
join trade in db.tblTrades on ttrade.trade_id equals trade.trade_id
join ttt in db.tblTradeTradeTypes on trade.trade_id equals ttt.trade_id
join tradet in db.tblTradeTypes on ttrade.trade_type_id equals tradet.trade_type_id
join cj in db.tblCustomerJobs on trade.trade_id equals cj.trade_id
join tr in db.tblTraderRatings on tt.UserId equals tr.UserId
//join tc in db.tblCustomers on cj.UserId equals tc.UserId
orderby tt.trader_firstname ascending
select new
{
tt.UserId
,
tt.trader_title
,
tt.trader_firstname
,
tt.trader_surname
,
tt.trader_phone1
,
tt.trader_phone2
,
tt.trader_working_area_id
,
tt.trader_overall_rating
,
trader_working_area_name = twal.trader_working_area_name.Substring(0, twal.trader_working_area_name.IndexOf('(')).Trim()
,
trader_working_area_postcodes = twal.trader_working_area_name.Substring(twal.trader_working_area_name.IndexOf('(') + 1, twal.trader_working_area_name.LastIndexOf(')') - twal.trader_working_area_name.IndexOf('(') - 1).Trim()
,
trade_type_name = tradet.trade_type_name == null ? "" : tradet.trade_type_name
,
trade.trade_name
,
ttrade.trade_type_id
,
ttrade.trade_id
,
tr.Rating01
,
tr.Rating02
,
tr.Rating03
,
tr.Rating04
,
tr.Rating05
}
).Distinct();
lvTrustAccounts.DataSource = query;
lvTrustAccounts.DataBind();
}
protected void lvTrustAccounts_ItemDataBound(object sender, ListViewItemEventArgs e)
{
Object dataRecord = ((ListViewDataItem)e.Item).DataItem; // Get the dataitem and place it into dataRecord
Type anonType = dataRecord.GetType(); // get the anonymous type
// Get user id and rating values using reflection
Guid userid = (Guid)anonType.GetProperty("UserId").GetValue(dataRecord, null);
int rating1 = (int)anonType.GetProperty("Rating01").GetValue(dataRecord, null);
int rating2 = (int)anonType.GetProperty("Rating02").GetValue(dataRecord, null);
int rating3 = (int)anonType.GetProperty("Rating03").GetValue(dataRecord, null);
int rating4 = (int)anonType.GetProperty("Rating04").GetValue(dataRecord, null);
int rating5 = (int)anonType.GetProperty("Rating05").GetValue(dataRecord, null);
// Put rating values in array
int[] rateValues = new int[]
{
rating1, rating2, rating3, rating4, rating5
};
// Get a reference to the rating control, and set and bind the data
Spaanjaars.Toolkit.ContentRating ratingControl = (Spaanjaars.Toolkit.ContentRating)e.Item.FindControl("ContentRating1");
if (e.Item.ItemType == ListViewItemType.DataItem)
{
ratingControl.ItemId = userid;
ratingControl.DataSource = rateValues;
ratingControl.DataBind();
}
}
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] GetCompletionList(string contextKey, string prefixText, int count)
{
// prefixText: the text the user has entered thus far
// count: the number of suggestions to return
// contextKey: the column name to fetch suggestions for
return new SelectCustomers().GetCompletionList(contextKey, prefixText, count);
}
}
|

March 31st, 2010, 06:29 AM
|
Registered User
|
|
Join Date: Mar 2010
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
db design
|

April 1st, 2010, 06:33 AM
|
 |
Wrox Author
Points: 72,055, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
|
|
Hi there,
This is a bit too much code for me to read and digest. Also, there are way too many dependencies (AJAX, Update Panels and so on). Can you try reproducing this in a simple scenario with, preferably a fake data source that doesn't rely on a database.
Cheers,
Imar
|

April 7th, 2010, 06:25 AM
|
Registered User
|
|
Join Date: Mar 2010
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
default.aspx page
Code:
<%@ Page Title="" Language="C#" MasterPageFile="~/SingleColumn.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="Spaanjaars.Toolkit" Namespace="Spaanjaars.Toolkit" TagPrefix="isp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
<!--********************************************************-->
<!--********Pulls in the contextKey needed for the dropdown filter********-->
<!--********************************************************-->
<script type="text/javascript">
function pageLoad(sender, args) {
var autoComplete = $find('autoComplete');
autoComplete.add_populating(function() {
// use the filter as the context key
autoComplete.set_contextKey($get('<%= this.ddlFilter.ClientID %>').value);
});
autoComplete.add_itemSelected(function() {
// force the panel to refresh
__doPostBack('<%= this.TrustAccountsUpdatePanel.ClientID %>', '');
});
}
</script>
<div class="validationAsterix">
* Indicates a required field.
</div>
<div>
<asp:Updatepanel ID="TrustAccountsUpdatePanel" runat="server" UpdateMode="Conditional">
<contentTemplate>
<div id="dlg" class="panelTrustAccounts" style="width:915px">
<div class="headerTrustAccounts" style="cursor:default">
<div class="outerTrustAccounts">
<div class="innerTrustAccounts">
<div class="contentTrustAccounts">
<h2>Trade Selector</h2>
</div>
</div>
</div>
</div>
<div class="bodyTrustAccounts">
<div class="outerTrustAccounts">
<div class="innerTrustAccounts">
<div class="contentTrustAccounts">
<%--************************************************************************--%>
<%--*************************ListView with DataSource****************************--%>
<%--************************************************************************--%>
<asp:LinqDataSource
ID="TrustsDataSource"
runat="server"
ContextTypeName="TradeSelectorDataContext"
TableName="tblCustomers" />
<asp:ListView
ID="lvTrustAccounts"
runat="server"
DataKeyNames="UserId"
DataMember="DefaultView"
OnItemDataBound="lvTrustAccounts_ItemDataBound"
OnPreRender="Page_PreRender">
<LayoutTemplate>
<table id="TrustAccounts" runat="server" class="gridTrustAccounts" cellspacing="0" border="0">
<tr>
<th><asp:LinkButton ID="btnSortTraderContact" runat="server" Text="Trader Contact Details" CommandName="Sort" CommandArgument="trader_firstname" Width="190px" /></th>
<th><asp:LinkButton ID="btnSortTraderDetails" runat="server" Text="Trader Details" CommandName="Sort" CommandArgument="trade_id" Width="110px" /></th>
<th><asp:LinkButton ID="btnSortTraderRating" runat="server" Text="Trader Overall Rating" CommandName="Sort" CommandArgument="trader_overall_rating" Width="150px" /></th>
</tr>
</table>
</LayoutTemplate>
<EmptyDataTemplate>
<table id="Table1" runat="server" style="">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<%--The line below allows for the itemtemplate (odd numbers) to also accommodate for the alternateitemtemplate (even numbers) as these two template are, in my case, a duplicate of each other. The style classes to use for each are specified after the "?".--%>
<tr class='<%# (Container.DataItemIndex % 2 == 0)?"row":"altrow" %>' id="row" runat="server" style="height:108px;">
<td>
<asp:ImageButton AlternateText="Trader" ID="ImageButtonTradesman" runat="server" ImageUrl="~/App_Themes/images/trademan10.png" />
<b>
<%# Eval("trader_title") %>. <%# Eval("trader_firstname") %> <%# Eval("trader_surname")%>
</b>
<br />
<asp:ImageButton AlternateText="Traders Phone Number" ID="ImageButtonPhone" runat="server" ImageUrl="~/App_Themes/images/phone15.jpg" />
<b>
<font color="green">
<%# Eval("trader_phone1") %>
</font>
</b>
<br />
<asp:ImageButton AlternateText="Traders Mobile Number" ID="ImageButtonMobile" runat="server" ImageUrl="~/App_Themes/images/mobile15.jpg" />
<b>
<font color="green">
<%# Eval("trader_phone2") %>
</font>
</b>
<%--<br />
<asp:ImageButton AlternateText="Email Trader" ID="ImageButtonEmail" runat="server" ImageUrl="~/App_Themes/images/email15.jpg" />
<a href="mailto:<%#Eval("customer_email")%>"><%#Eval("trader_email")%></a>--%>
</td>
<td>
<b>
<%# Eval("trade_type_name")%> <%# Eval("trade_name") %>
</b>
within
<b>
<%# Eval("trader_working_area_name")%>
</b>
</td>
<td>
<isp:ContentRating
ID="ContentRating1"
runat='server'
LegendText="rates: {0} avg: {1}" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<%--*****************************************************************************--%>
<%--*****************************End List View***********************************--%>
<%--*****************************************************************************--%>
</div>
</div>
</div>
</div>
<div class="footerTrustAccounts">
<div class="outerTrustAccounts">
<div class="innerTrustAccounts">
<div class="contentTrustAccounts"></div>
</div>
</div>
</div>
</div>
</contentTemplate>
</asp:Updatepanel>
</div>
</asp:Content>
|
Thread Tools |
Search this Thread |
|
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |