按正确的列(即 TemplateField)对 gridView 进行排序
我在 gridView 中排序列时遇到问题。我只想选择列中名称等于“Finished”的行。
我的 gridView 由几个 BoundField 和 TamplateFields 组成。当我想按正确的 BoundField 排序时,我将正确的字符串放入属性 FilterExpression 中。例如:
GridView 中的字段:
所以我设置 FilterExpression = "[identifier] LIKE '%" + txtCaseNumber.Text + "%'"
其中 identifier 是 BoundField 中的 DataField,在这种情况下一切正常。 但是,当我想从 TempateField 中名称等于 Fininish 的列中选择正确的行时,我不知道应该如何做。 TemplateField 的示例如下所示:
<asp:TemplateField HeaderText="Status" SortExpression="Status">
<ItemTemplate>
<asp:Label ID="lblStatus" runat="server" Text='<%# Utils.ConvertToProcessStatus((int)Eval("status"))%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
如果有人知道我该怎么做?
感谢您的帮助。
没关系,但我忘了提到我有自己的用户控件(ucCaseFilter),它由我从中选择状态的 DropDownList 组成。例如:失败、进行中、完成...在此控件内,我创建公共属性过滤器,我想分配字符串值,该值将选择正确的列并对它们进行排序。
Filter = "[???] = '" + ddlCaseStatus.SelectedValue + "'";
然后在 gridView 中使用它:
FilterExpression = ucCaseFilter.Filter;
我不知道如何获取列名称或其他方法来让我按“状态”列排序。
如果我不明白之前的回答并且它指的是正确的解决方案
I have got problem with sorting column in gridView. I want to select only those rows in column which name equal for example "Finished"
My gridView consists of few BoundField and TamplateFields. When I want to sort by proper BoundField I put proper string to property FilterExpression. For example:
Field in GridView:<asp:BoundField DataField="identifier" HeaderText="Case number" SortExpression="identifier" />
so I setFilterExpression = "[identifier] LIKE '%" + txtCaseNumber.Text + "%'"
where identifier is DataField in BoundField and In this case everything is ok.
But when I want to select proper rows from column wihich name equal Fininish from TempateField I don't know how I should do it.
Exaple of TemplateField looks like this:
<asp:TemplateField HeaderText="Status" SortExpression="Status">
<ItemTemplate>
<asp:Label ID="lblStatus" runat="server" Text='<%# Utils.ConvertToProcessStatus((int)Eval("status"))%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
If anyone know how I can do it??
Thanks for help.
It's ok but I forgot mention that I have my own user contron (ucCaseFilter) which consists of DropDownList from which I choose status. For example: Failed, InProgress, Finish ... Inside this control I create public property Filter and I want to assign string value which will be select proper column and sort them .
Filter = "[???] = '" + ddlCaseStatus.SelectedValue + "'";
Then in gridView use it:
FilterExpression = ucCaseFilter.Filter;
I don't know how get column name or other approach which afford me sort by "Status" column.
If I didn't understand previous answerd and it refer to correct soluti
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改您的
以添加带有LinkButton
的
标记,如下所示: >grd_RowCommand 事件处理“排序”命令并使用
CommandArgument
构建过滤字符串Change your
<asp:TempleteField />
to add<HeaderTemplate />
markup with aLinkButton
like this:and in
grd_RowCommand
event handle "Sort" command and use theCommandArgument
to build your filter string