DataGrid的一个关于变量的问题:在页面里如何引用cs文件里的变量呢?
<asp:datagrid id="DataGrid1" runat="server">
<Columns>
<asp:BoundColumn HeaderText="序号" DataField=<%=sortid%>/> <asp:HyperLinkColumn HeaderText="名称" DataNavigateUrlField=<%=sortid%> DataNavigateUrlFormatString="infoshow.aspx?id={0}" DataTextField=<%=sorttitle%>/>
......................
.cs文件里面我定义了如下变量:
据个例子来说:
public void show(string showname)
{
switch(showname)
{
case "infoshow":
sortid="info_id";
sorttitle="info_title";
sorttable="t_info";
break;
...........
}
MySql="select "+sortid+","+sorttitle+" from "+sorttable;
DataAccess db = new DataAccess();
DataSet show = db.GetDataSet(MySql,"aa");
DataGrid1.DataSource=show.Tables[0].DefaultView;
DataGrid1.DataBind();
}
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
private void LinkButton_infoshow_Click(object sender, System.EventArgs e)
{
showname="infoshow";
show(showname);
}
错误提示为:
选定数据源上未能找到名称为“<%=sortid%>”的字段或属性。
请问:怎么回事?
我该如何用?
相关推荐
WPF Datagrid 合并单元格
WPF Datagrid 合并单元格 复杂表头 支持位置拖动、 列宽度拖动,组内列会按比例自动调整 ;
wpf datagrid数据导出到execl
private void daochu_Click(object sender, RoutedEventArgs e) { System.Windows.Controls.DataGrid DataGrid = dataGrid1; string file = "C:Users\\Administrator\\Desktop\\qb"; Export(DataGrid, file); } public static void Export(System.Windows.Controls.DataGrid dataGrid, string _fileName) { System.Data.DataTable dt = new System.Data.DataTable(); for (int i = 0; i < dataGrid.Columns.Count; i++) { if (dataGrid.Columns[i].Visibility == System.Windows.Visibility.Visible)//只导出可见列 { dt.Columns.Add(dataGrid.Columns[i].Header.ToString());//构建表头
在Asp.net中使用DataGrid分页
此实例程序使用DataGrid控件的AllowPaging属性可以为Web页面很方便地实现页面功能
EasyUI的tree及datagrid真实使用范例
EasyUI的tree及datagrid的综合应用
ASP.NET中为DataGrid添加合计字段
论坛中最常见的一个问题是:“ 我怎样在 DataGrid 中显示列合计?”。 我亲自多次为这个问题提供了示例代码,因此,我想在DotNetJunkies 的标题中提供这么一份指南。 在这份指南中你将会学到怎样在 DataGrid 中编程实现对某一列的值进行统计,并在 DataGrid 的页脚中显示其合计值。这份指南中供下载的示例中包括了 C# 和 Visual Basic.NET 两种代码。 这份指南的最终结果看起来像这样: 从上图可看出: 上面所用到的屏幕图片中的 DataGrid 是一个非常典型的 DataGrid 。有许多控制 DataGrid 外观的属性,它使用两个 BoundC


