| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 604 人关注过本帖
标题:关于datagril超级链接问题
只看楼主 加入收藏
abccjyj
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-5-22
收藏
 问题点数:0 回复次数:1 
关于datagril超级链接问题

我在aspx.cx中有datagril的如下代码。但不知怎么将第一列(fchrTopicCaption)做成超级链接。
在aspx中加入如下,又报在数据源中找不到fchrTopicCaption。请诸位帮忙解决 先谢谢 了
++++++++++++++++++++++++++++++++++++++++++++
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="fchrFunctionID" DataTextField="fchrTopicCaption" HeaderText="标题"
NavigateUrl="ForumList.aspx?fchrFunctionID=(0)"></asp:HyperLinkColumn>
</Columns>
+++++++++++++++++++++++++++++++++++++++++++
aspx 代码:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
DataGridDataBind();
}
}
//绑定数据
private void DataGridDataBind()
{
string id=Request.QueryString["fchrFunctionID"];//传递来的ID
DataSet ds = GetCustomersData(id);

recordCount = ds.Tables[0].Rows.Count;
//获取当前的页数
pageCount = (int)Math.Ceiling( recordCount * 1.0 / PageSize);
//避免纪录从有到无时,并且已经进行过反页的情况下CurrentPageIndex > PageCount出错
if(recordCount ==0)
{
this.dgrTopicList.CurrentPageIndex = 0;
}
else if(this.dgrTopicList.CurrentPageIndex >= pageCount)
{
this.dgrTopicList.CurrentPageIndex = pageCount - 1;
}
DataView dv = ds.Tables[0].DefaultView;
this.dgrTopicList.DataSource = dv;
this.dgrTopicList.DataBind();
NavigationStateChange();
}
//数据绑定
public static DataSet GetCustomersData(string id)
{
string sql = "SELECT fchrTopicID,主题标题=fchrTopicCaption,发贴人=fchrOperatorName,回复=fintTopicreply,查看=fintTopiclook FROM T_Topic where fchrFunctionID='"+id+"'";
SqlConnection oConn = new SqlConnection(CONNSTRING);
SqlCommand oCommand = new SqlCommand(sql,oConn);
SqlDataAdapter dataAdapter = new SqlDataAdapter(oCommand);
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
return ds;
}

/// <summary>

/// 控制导航按钮或数字的状态

/// </summary>

public void NavigationStateChange()

{
if( PageCount <= 1 )//( RecordCount <= PageSize )//小于等于一页
{
this.LBtnFirst.Enabled = false;
this.LBtnPrev.Enabled = false;
this.LBtnNext.Enabled = false;
this.LBtnLast.Enabled = false;
}
else //有多页
{
if( PageIndex == 0 )//当前为第一页
{
this.LBtnFirst.Enabled = false;
this.LBtnPrev.Enabled = false;
this.LBtnNext.Enabled = true;
this.LBtnLast.Enabled = true;
}
else if( PageIndex == PageCount - 1 )//当前为最后页
{
this.LBtnFirst.Enabled = true;
this.LBtnPrev.Enabled = true;
this.LBtnNext.Enabled = false;
this.LBtnLast.Enabled = false;
}
else //中间页
{
this.LBtnFirst.Enabled = true;
this.LBtnPrev.Enabled = true;
this.LBtnNext.Enabled = true;
this.LBtnLast.Enabled = true;
}
}

if(RecordCount == 0)//当没有纪录时DataGrid.PageCount会显示1页
this.LtlPageCount.Text = "0";
else
this.LtlPageCount.Text = PageCount.ToString();
if(RecordCount == 0)
this.LtlPageIndex.Text = "0";
else
this.LtlPageIndex.Text = (PageIndex + 1).ToString();//在有页数的情况下前台显示页数加1
this.LtlPageSize.Text = PageSize.ToString();
this.LtlRecordCount.Text = RecordCount.ToString();
}
// 总页数
public int PageCount
{
get{return this.dgrTopicList.PageCount;}
}
//页大小
public int PageSize
{
get{return this.dgrTopicList.PageSize;}
}
//页索引,从零开始
public int PageIndex
{
get{return this.dgrTopicList.CurrentPageIndex;}
set{this.dgrTopicList.CurrentPageIndex = value;}
}
// 纪录总数
public int RecordCount
{
get{return recordCount;}
set{recordCount = value;}
}
public static string CONNSTRING
{
get
{
connect_strings oConn = new connect_strings();
return oConn.SqlConnectionString;
}
}
public void DoGoToForum(Object oSource,DataGridCommandEventArgs oArgs)
{
int intCurRow = oArgs.Item.ItemIndex;
string strCurTopicID = dgrTopicList.Items[intCurRow].Cells[1].Text;
Response.Redirect("ForumList.aspx?id=" +strCurTopicID+"&UID="+Request.QueryString["UID"]);
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.LBtnFirst.Click += new System.EventHandler(this.LBtnNavigation_Click);
this.LBtnPrev.Click += new System.EventHandler(this.LBtnNavigation_Click);
this.LBtnNext.Click += new System.EventHandler(this.LBtnNavigation_Click);
this.LBtnLast.Click += new System.EventHandler(this.LBtnNavigation_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
private void LBtnNavigation_Click(object sender, System.EventArgs e)
{
LinkButton btn = (LinkButton)sender;
switch(btn.CommandName)
{
case "First":
PageIndex = 0;
break;
case "Prev"://if( PageIndex > 0 )
PageIndex = PageIndex - 1;
break;
case "Next"://if( PageIndex < PageCount -1)
PageIndex = PageIndex + 1;
break;
case "Last":
PageIndex = PageCount - 1;
break;
}
DataGridDataBind();
}
}
}

搜索更多相关主题的帖子: datagril 链接 超级 aspx 
2006-08-01 18:27
abccjyj
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-5-22
收藏
得分:0 

版主能不能帮忙解决一下

2006-08-02 17:59
快速回复:关于datagril超级链接问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026825 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved