[英]String was not recognized as a valid boolean on sorting
我試圖將排序功能添加到舊的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());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.