N,V,C,D是my GridView绑定列中的变量。
当我在我的GridView中显示这个表时,我希望显示新建、验证、取消、删除的。
我的GridView调用数据库中运行select查询的过程。我需要更改查询还是添加GridView函数?我不想更改我的数据库值本身。
我该怎么做?
到目前为止,这是我的领域:
<asp:BoundField
DataField="Status"
HeaderText="Status"
SortExpression="Status" />发布于 2014-04-04 09:35:48
首先,我从默认的中编辑了GridViewControl的GridViewControl状态BoundField列,并将其更改为ItemTemplate。
(我删除了自动生成的EditItemTemplate标记)
<asp:Label ID="lblStatus"
runat="server"
Text='<%# GetLabelText(Eval("status")) %>'>
</asp:Label>然后在CS文件中添加了以下代码:
public string GetLabelText(object dataItem)
{
string text = "";
string val = dataItem as string;
switch (val)
{
case "N": text = "New";
break;
case "V": text = "Verified";
break;
case "F": text = "Fulfilled";
break;
case "C": text = "Cancelled";
break;
}
return text;
}这就像一种魅力。谢谢你的帮助,伙计们!
发布于 2014-04-04 07:36:41
这在C#中应该是可能的--至少如果您只显示值而不编辑它们的话。在CellFormatting事件中,您可以简单地更改要显示的值。
private void gridview_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.Value.equals("N")) e.Value = "New";
else if(e.Value.equals("V")) e.Value = "Verified";
else if(e.Value.equals("C")) e.Value = "Cancelled";
else if(e.Value.equals("D")) e.Value = "Deleted";
}我现在手头还没有C#,所以可能会有排字。就试一下。
发布于 2014-04-04 07:38:31
在你的询问中,
Select
YourFields
case
when YourConditionField= 'N' then 'New'
when YourConditionField= 'V' then 'Verified'
when YourConditionField= 'C' then 'Cancelled'
when YourConditionField= 'D' then 'Deleted'
end,
from table第一次在GridView,
可以使用RowDataBound事件,需要将带有标签的模板列添加到网格视图中。
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="labelResult" runat="server" />
</ItemTemplate>
</asp:TemplateField>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
string value = e.Row.Cells[0].Text;
Next find the label in the template field.
Label myLabel = (Label) e.Row.FindControl("myLabel");
if (value == "N")
{
myLabel.Text = "New";
}
else if (value == "V")
{
myLabel.Text = "Verified";
}
else if (value == "C")
{
myLabel.Text = "Cancelled";
}
else if (value == "D")
{
myLabel.Text = "Deleted";
}
}
}https://stackoverflow.com/questions/22856045
复制相似问题