如果value为true,则更新SQL列

编程入门 行业动态 更新时间:2024-10-28 05:21:17
本文介绍了如果value为true,则更新SQL列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一点值(在状态中)我想在gridview中显示其状态,如果为true,则行显示Active,否则行显示Inactive,这是我的代码,但结果显示为True或虚假本身。并且基于Active或Inactive,Action列必须显示Deactivate或Activate

ShopNumber ShopName地址网站状态操作设置 2 abc Kuwait xyz True取消激活编辑 3 def科威特deuuy False激活编辑 4 主要次要Usra True激活编辑 5 Isys Kuwait isys False激活编辑 6 Avenues Kuwait avenues False激活编辑

这是代码隐藏:

protected void GridView1_RowDataBound( object sender,GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Boolean bitCheck = Convert.ToBoolean(e.Row.Cells [ 4 ]。Text); if (bitCheck) { e.Row.Cells [ 4 ]。Text = Active; } else { e.Row.Cells [ 4 ]。文本= 无效; } }

这是ASP代码:

< asp:GridView ID = GridView1 runat = server AllowPaging = True AutoGenerateColumns = False DataSourceID = SqlDataSource1 AllowSorting = True onselectedindexchanged = GridView1_SelectedIndexChanged DataKeyNames = TempID > < 列 > < asp:BoundField DataField = ShopNumber HeaderText = ShopNumber SortExpression = ShopNumber > < ItemStyle 宽度 = 150px > < / ItemStyle > < / asp:BoundField > < asp:BoundField DataField = ShopName HeaderText = ShopName SortExpression = ShopName > < ItemStyle 宽度 = 170px > < / ItemStyle > < / asp:BoundField > < asp:BoundField DataField = 地址 HeaderText = 地址 SortExpression = 地址 > < ItemStyle 宽度 = 170px > < / ItemStyle > < / asp:BoundField > < asp:BoundField DataField = 网站 HeaderText = 网站 SortExpression = 网站 > < ItemStyle 宽度 = 150px > < / ItemStyle > < / asp:BoundField > < asp:TemplateField HeaderText = 状态 SortExpression = 状态 > < EditItemTemplate > < asp:TextBox ID = textStatus runat = 服务器 文字 =' <% #Bind( 状态)%>' > < / asp:TextBox > < / EditItemTemplate > < ItemTemplate > < asp:Label ID = Label2 runat = server 文本 =' <% #Bind( 状态)%>' > < / asp:Label > < / ItemTemplate > < ItemStyle 宽度 = 150px / > < / asp:TemplateField > < asp:TemplateField HeaderText = 行动 SortExpression = 行动 > < EditItemTemplate > < asp:TextBox ID = textAction runat = 服务器 正文 =' <% #Bind( 操作)%>' > < / asp:TextBox > < / EditItemTemplate > < ItemTemplate > < asp:标签 ID = Label1 runat = server 文本 =' <% #Bind( 操作)%>' > < / asp:标签 > < / ItemTemplate > < ItemStyle 宽度 = 150px / > < / asp:TemplateField > < asp: CommandField HeaderText = 设置 ShowEditButton = True > < ItemStyle 宽度 = 150px > < / ItemStyle > < / asp:CommandField >

解决方案

您好, 试试这个。它会工作。

protected void GridView1_RowDataBound(object sender,GridViewRowEventArgs e) { if(e.Row) .RowType == DataControlRowType.DataRow) { Label Label2 =(Label)e.Row.FindControl(Label2); Label Label1 =(Label)e.Row.FindControl(Label1); if(Convert.ToBoolean(Label2.Text.Trim())) { Label2.Text =Active; Label1.Text =激活; } else if(!Convert.ToBoolean(Label2.Text.Trim())) { Label2.Text =Inactive; Label1.Text =停用; } } }

遗漏:OnRowDataBound =GridView1_RowDataBound 在你的Gridview控件中

< asp:GridView ID = GridView1 runat = server AllowPaging = True AutoGenerateColumns = False DataSourceID = SqlDataSource1 AllowSorting = True onselectedindexchanged = GridView1_SelectedIndexChanged DataKeyNames = TempID>

I have a bit value (in Status) i want to display its status in gridview as if true, the row display "Active", otherwise the row display "Inactive", this is my code, but the result displays True or false itself. And based on the Active or Inactive, the Action column must display Deactivate or Activate

ShopNumber ShopName Address Website Status Action Settings 2 abc Kuwait xyz True Deactivate Edit 3 def Kuwait deuuy False Activate Edit 4 Major Minor Usra True Activate Edit 5 Isys Kuwait isys False Activate Edit 6 Avenues Kuwait avenues False Activate Edit

Here is the codebehind:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Boolean bitCheck = Convert.ToBoolean(e.Row.Cells[4].Text); if (bitCheck) { e.Row.Cells[4].Text = "Active"; } else { e.Row.Cells[4].Text = "Inactive"; } }

Here is ASP code:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" AllowSorting="True" onselectedindexchanged="GridView1_SelectedIndexChanged" DataKeyNames="TempID"> <Columns> <asp:BoundField DataField="ShopNumber" HeaderText="ShopNumber" SortExpression="ShopNumber" > <ItemStyle Width="150px"></ItemStyle> </asp:BoundField> <asp:BoundField DataField="ShopName" HeaderText="ShopName" SortExpression="ShopName" > <ItemStyle Width="170px"></ItemStyle> </asp:BoundField> <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" > <ItemStyle Width="170px"></ItemStyle> </asp:BoundField> <asp:BoundField DataField="Website" HeaderText="Website" SortExpression="Website" > <ItemStyle Width="150px"></ItemStyle> </asp:BoundField> <asp:TemplateField HeaderText="Status" SortExpression="Status"> <EditItemTemplate> <asp:TextBox ID="textStatus" runat="server" Text='<%# Bind("Status") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("Status") %>'></asp:Label> </ItemTemplate> <ItemStyle Width="150px" /> </asp:TemplateField> <asp:TemplateField HeaderText="Action" SortExpression="Action"> <EditItemTemplate> <asp:TextBox ID="textAction" runat="server" Text='<%# Bind("Action") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("Action") %>'></asp:Label> </ItemTemplate> <ItemStyle Width="150px" /> </asp:TemplateField> <asp:CommandField HeaderText="Settings" ShowEditButton="True" > <ItemStyle Width="150px"></ItemStyle> </asp:CommandField>

解决方案

Hi, Try this. It will work.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Label Label2 = (Label)e.Row.FindControl("Label2"); Label Label1 = (Label)e.Row.FindControl("Label1"); if (Convert.ToBoolean(Label2.Text.Trim())) { Label2.Text = "Active"; Label1.Text = "Activate"; } else if(!Convert.ToBoolean(Label2.Text.Trim())) { Label2.Text = "Inactive"; Label1.Text = "Deactivate"; } } }

Just Missing : OnRowDataBound="GridView1_RowDataBound" In your Gridview control

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" AllowSorting="True" onselectedindexchanged="GridView1_SelectedIndexChanged" DataKeyNames="TempID">

更多推荐

如果value为true,则更新SQL列

本文发布于:2023-10-20 09:16:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1510559.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:则更   true   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!