【发布时间】:2013-12-03 16:29:45
【问题描述】:
我正在尝试向旧的 asp:Gridview 添加排序功能,但由于某种原因,使用它确实很痛苦。我尝试了多种不同的方法,但都失败了。我真的很感激这方面的一些帮助。我查看了 The Code Project 和 MSDN 中的示例,但没有任何帮助。这是我最新的代码:
<asp:SqlDataSource ID="grdVwCustomer_DataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:DBConnectingString %>">
</asp:SqlDataSource>
<asp:Gridview ID="grdVwCustomer" runat="server" AutoGenerateColumns="false"
AllowSorting="true" DataKeyNames="CustomerID" OnSorting="grdVwCustomer_Sorting"
DataSourceID="grdVwCustomer_DataSource">
<asp:TemplateField HeaderText="User Name" SortExpression="UserName">
<ItemTemplate>
<%# DataBinder.Eval( Container.DataItem, "UserName" )%>
</ItemTemplate>
</asp:TempateField>
</asp:Gridview>
protected void Page_Load( object sender, EventArgs e )
{
string query = "SELECT * FROM vPanel_Customer WHERE DeletionStateCode=0";
grdVwCustomer_DataSource.SelectCommand = query;
grdVwCustomer.DataBind();
}
protected void grdVwCustomer_Sorting(object sender, GridViewSortEventArgs e)
{
DataBind(Convert.ToBoolean(e.SortExpression)); ****this line gets the error****
}
编辑:
protected void grdVwCustomer_Sorting(object sender, GridViewSortEventArgs e)
{
switch (e.SortExpression)
{
case "UserName":
if (e.SortDirection == SortDirection.Ascending)
{
String queryString = "SELECT * FROM vPanel_Customer WHERE DeletionStateCode=0 ORDER BY UserName";
DataSet ds = GetData(queryString);
if (ds.Tables.Count > 0)
{
grdVwCustomer.DataSource = ds;
grdVwCustomer.DataBind();
}
else
{
//show message to user
}
}
break;
}
}
DataSet GetData(String queryString)
{
// Retrieve the connection string stored in the Web.config file.
String connectionString = ConfigurationManager.ConnectionStrings["DBConnectingString"].ConnectionString;
DataSet ds = new DataSet();
try
{
// Connect to the database and run the query.
SqlConnection connection = new SqlConnection(connectionString);
SqlDataAdapter adapter = new SqlDataAdapter(queryString, connection);
// Fill the DataSet.
adapter.Fill(ds);
}
catch (Exception ex)
{
Logging.Log.LogException(Forbin.Logging.PageType.CustomerManage, Logging.MessageType.Exception, ex.ToString());
UIUtils.ShowMessageToUser("OnErrorMesg", this.Page);
}
return ds;
}
错误Guid should be 32 digits... 显示在这一行 CustomerID = new Guid(e.CommandArgument.ToString());
【问题讨论】:
-
那么...问题出在哪一行?
-
已编辑原始帖子以显示哪一行出现错误,感谢@Jason 指出这一点
标签: c# asp.net sorting gridview