各位大俠,最近小弟想開發一個分頁控件,該控件繼承了Repeater控件,我在類裏面定義了幾個分頁的屬性,當我把這個自定義控件拉到VS2005的某個頁面,並用設計器顯示,它有時候會報錯,即控件顯示不出來,在設計器中顯示,出現這種情況時,我把VS2005關閉,然後再開起來,它有變好了!我想請問一下,是什麼原因引起的呢?是我的VS2005的問題,還是我的代碼那裏沒有處理好呢?
設計器出錯畫面:

類代碼如下(代碼還沒有寫完)
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace Toiletry.UI
{
/// <summary>
/// 繼承Repeater控件,添加分頁功能
/// </summary>
[ToolboxData("<{0}:DataRepeater runat='server' RecordCount=\"100\"><HeaderTemplate><table><tr><td>Header1</td><td>Header2</td></tr></HeaderTemplate><ItemTemplate><tr><td>Data1</td><td>Data2</td></tr></ItemTemplate><FooterTemplate></table></FooterTemplate> </{0}:DataRepeater>")]
public class DataRepeater : System.Web.UI.WebControls.Repeater
{
[Category("分頁")]
[DefaultValue(0)]
public int RecordCount
{
get
{
object o = ViewState["RecordCount"];
return o == null ? 0 : Convert.ToInt32(o);
}
set
{
ViewState["RecordCount"] = value;
}
}
[Category("分頁")]
[DefaultValue(0)]
public virtual int PageIndex
{
get
{
object o = ViewState["PageIndex"];
return o == null ? 0 : Convert.ToInt32(o);
}
set
{
ViewState["PageIndex"] = value;
}
}
[Category("分頁")]
[DefaultValue(10)]
public virtual int PageSize
{
get
{
object o = ViewState["PageSize"];
return o == null ? 10 : Convert.ToInt32(o);
}
set
{
ViewState["PageSize"] = value;
}
}
[Category("分頁")]
[DefaultValue(true)]
public bool EnablePaging
{
get
{
object o = ViewState["EnablePaging"];
return o == null ? true : Convert.ToBoolean(o);
}
set
{
ViewState["EnablePaging"] = value;
}
}
public override void RenderControl(HtmlTextWriter writer)
{
Table PageTable = new Table();
PageTable.RenderBeginTag(writer);
#region "Data Row"
TableRow DataRow = new TableRow();
DataRow.RenderBeginTag(writer);
//Data Cell
TableCell DataCell = new TableCell();
DataCell.RenderBeginTag(writer);
//Repeater控件的內容
base.RenderControl(writer);
DataCell.RenderEndTag(writer);
DataRow.RenderEndTag(writer);
#endregion
//允許分頁時,才呈現分頁控件
if (EnablePaging == true)
{
#region "Page Row"
TableRow PageRow = new TableRow();
PageRow.RenderBeginTag(writer);
//Page Cell
PageCell PCell = new PageCell(RecordCount, PageIndex, PageSize);
PageRow.Cells.Add(PCell);
PageRow.RenderControl(writer);
PageRow.RenderEndTag(writer);
#endregion
}
PageTable.RenderEndTag(writer);
}
}
public class PageCell : System.Web.UI.WebControls.TableCell
{
/// <summary>
/// 總記錄數
/// </summary>
private int _RecordCount;
/// <summary>
/// 當前頁碼[索引從0開始,即0=第1頁]
/// </summary>
private int _PageIndex;
/// <summary>
/// 每頁顯示的記錄筆數
/// </summary>
private int _PageSize;
/// <summary>
/// 總共有多少頁
/// </summary>
private int _PageCount;
/// <summary>
/// 在分頁控件上,顯示多少個[頁碼鏈接]
/// </summary>
private int _PageLinkCount = 8;
/// <summary>
/// 構造函數
/// </summary>
/// <param name="RecordCount">總記錄數</param>
/// <param name="PageIndex">當前頁碼[索引從0開始,即0=第1頁]</param>
/// <param name="PageSize">每頁顯示的記錄筆數</param>
public PageCell(int RecordCount, int PageIndex, int PageSize)
{
_RecordCount = RecordCount;
_PageIndex = PageIndex;
_PageSize = PageSize;
//_PageSize=0的異常
if (_PageSize == 0)
{
_PageSize = 10;
}
//求一共有幾頁
if (_RecordCount % _PageSize == 0)
{
_PageCount = _RecordCount / _PageSize;
}
else
{
_PageCount = _RecordCount / _PageSize + 1;
}
//產生分頁控件
InitPageControl();
}
/// <summary>
/// 產生分頁控件
/// </summary>
public virtual void InitPageControl()
{
//當前是第幾頁
int CurrentPageIndex = _PageIndex + 1;
//頁碼排列的中間值
int MiddleValue = 0;
//頁碼排列中間左邊有幾個
int LeftCount = 0;
//頁碼排列中間右邊有幾個
int RightCount = 0;
if (_PageLinkCount % 2 == 0)
{
MiddleValue = _PageLinkCount / 2 + 1;
LeftCount = _PageLinkCount / 2;
RightCount = _PageLinkCount / 2 - 1;
}
else
{
MiddleValue = (_PageLinkCount - 1) / 2 + 1;
LeftCount = (_PageLinkCount - 1) / 2;
RightCount = (_PageLinkCount - 1) / 2;
}
//當前頁碼<=中間值
if (CurrentPageIndex <= MiddleValue)
{
if (_PageCount >= _PageLinkCount)
{
for (int i = 1; i <= _PageLinkCount; i++)
{
LinkButton PageLink = new LinkButton();
PageLink.Text = i.ToString();
//分隔符
Literal PageBlank = new Literal();
PageBlank.Text = " ";
//add to control
this.Controls.Add(PageLink);
this.Controls.Add(PageBlank);
}
}
else
{
for (int i = 1; i <= _PageCount; i++)
{
LinkButton PageLink = new LinkButton();
PageLink.Text = i.ToString();
//分隔符
Literal PageBlank = new Literal();
PageBlank.Text = " ";
//add to control
this.Controls.Add(PageLink);
this.Controls.Add(PageBlank);
}
}
}
else
{
//當前頁碼>中間值
//處理原則,是把當前頁作為頁碼排列的中間值處理
//左部分
for (int i = 1; i <= LeftCount;i++)
{
LinkButton PageLink = new LinkButton();
PageLink.Text = (CurrentPageIndex - MiddleValue + 1).ToString();
//分隔符
Literal PageBlank = new Literal();
PageBlank.Text = " ";
//add to control
this.Controls.Add(PageLink);
this.Controls.Add(PageBlank);
}
//中間值
LinkButton MidPageLink = new LinkButton();
MidPageLink.Text = CurrentPageIndex.ToString();
//分隔符
Literal MidPageBlank = new Literal();
MidPageBlank.Text = " ";
//add to control
this.Controls.Add(MidPageLink);
this.Controls.Add(MidPageBlank);
//右部分
if (_PageCount - CurrentPageIndex >= RightCount)
{
for (int i = 1; i <= RightCount; i++)
{
LinkButton PageLink = new LinkButton();
PageLink.Text = (CurrentPageIndex + i).ToString();
//分隔符
Literal PageBlank = new Literal();
PageBlank.Text = " ";
//add to control
this.Controls.Add(PageLink);
this.Controls.Add(PageBlank);
}
}
else
{
for (int i = 1; i <= _PageCount - CurrentPageIndex; i++)
{
LinkButton PageLink = new LinkButton();
PageLink.Text = (CurrentPageIndex + i).ToString();
//分隔符
Literal PageBlank = new Literal();
PageBlank.Text = " ";
//add to control
this.Controls.Add(PageLink);
this.Controls.Add(PageBlank);
}
}
}
}
}
}
WEB頁面的
aspx代碼:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataRepeaterDemo.aspx.cs" Inherits="DataRepeaterDemo" %>
<%@ Register Assembly="Toiletry.UI" Namespace="Toiletry.UI" TagPrefix="cc1" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>未命名頁面</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<cc1:DataRepeater ID="rpList" runat="server" RecordCount="1001" EnablePaging="true">
<HeaderTemplate>
<table class="tby">
<tr>
<th>Age</th>
<th>Name</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Eval("Age")%></td>
<td><%#Eval("Name")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</cc1:DataRepeater>
<cc1:DataRepeater ID="DataRepeater1" runat="server" RecordCount="100">
<HeaderTemplate>
<table class="tby">
<tr>
<th>Age</th>
<th>Name</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Eval("Age")%></td>
<td><%#Eval("Name")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</cc1:DataRepeater>
<cc1:DataRepeater ID="DataRepeater2" runat="server" RecordCount="100" EnablePaging="false">
<HeaderTemplate>
<table>
</table>
<tr>
<td>
Header1</td>
<td>
Header2</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
Item1</td>
<td>
Item2</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table></FooterTemplate>
</cc1:DataRepeater>
</div>
</form>
</body>
</html>
大家好!
我是一个VC++的陌生者,但最近公司开发的项目中,有一个要求要用到OCX控件,即某个WEB页面要调整OCX的某个方法来启动系统的某个进程。
今天我找了一些资料并动手做了一下,有的做成功了,但有的失败,即WEB没有办法调用,我不青楚那里错了。如果边位看到并有时间,麻烦帮我看看。
首先我参照
http://www.codeproject.com/KB/atl/com_atl.aspx,我下载了这个页面的源码,并作了一些修正,使Test_ALT控制台程序可以跑起来,
我修正后的源码:
http://files.cnblogs.com/Akuan/TestActivex.rar从codeproject下载回来的源码,由于文件夹的目录改变了,因而我对Test_ATL.cpp文件的开始部分的一些代码进行了改变。这样控制台程序就可以正常运行。
然后我在原来的Simple_ATL项目中添加了一个Test.htm页面,代码如下:
<HTML>
<HEAD>
<TITLE>New Page</TITLE>
<script language="javascript">
function doTest()
{
var sum;
try
{
sum = SimpleATL.AddNumbers(3,4);
alert(sum);
}
catch(e)
{
alert(e.Message);
}
finally
{
sum=null;
}
}
</script>
</HEAD>
<BODY>
<OBJECT ID="SimpleATL" CLASSID="CLSID:970599E0-2673-11D3-A8A8-00105AA943DF">
</OBJECT>
<input type="button" value="测试加法" id="btnOK" onclick="doTest();" />
</BODY>
</HTML>
其中CLASSID的值来自于Simple_ATL项目的Simple_ATL.rdl文件中
library SIMPLE_ATLLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
uuid(970599E0-2673-11D3-A8A8-00105AA943DF),
helpstring("First_ATL Class")
]
coclass First_ATL
{
[default] interface IFirst_ATL;
};
};
但我打开Test.htm页面时,总是调用不成功AddNumbers方法。
如果那位对这方面比较熟悉的,麻烦帮我解决一下,谢谢。QQ:156834293.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<%
Dim oXML, oXMLError, ReturnValue, x
' Initial component
Set oXML = Server.CreateObject("MSXML2.DOMDocument")
' Set properties
oXML.async = false
oXML.setProperty "ServerHTTPRequest", true
' Load XML
'ReturnValue = oXML.Load(server.MapPath("test.xml"))
ReturnValue = oXML.loadXML("<Persons><Person name='mart'><Name>워드프레스</Name><Mobile>789XXXXXXXX</Mobile></Person><Person name='tttt'><Name>tttt</Name><Mobile>789XXXXXXXX</Mobile></Person></Persons>")
' Get data
Set objNode = oXML.getElementsByTagName("Name")
For x=0 to objNode.length-1
Response.Write objNode.item(x).Text&"<br/>"
Next
Set oXML = Nothing
response.Write("ddd")
%>
</body>
</html>
我已經把上面的CODE儲存為UTF-8了,但是讀取那幾個韓文總是出錯,小弟我不解,希望園子裏的朋友幫我看下,應怎樣修改,才可以讓韓文顯示正確。
如果大家覺得放在首頁不合適,請原諒,因為我現在被這個問題卡住了。