GridView 实现类似图片'发布'功能

 
'发布'在数据库中时一个字段 ,前台代码
    <asp:GridView ID="GridView1"  CellSpacing="7"  Width="780px" runat="server" CellPadding="6" 
               AutoGenerateColumns="False" onrowediting="GridView1_RowEditing" 
               onrowupdating="GridView1_RowUpdating" 
               onrowcancelingedit="GridView1_RowCancelingEdit" 
               EnableModelValidation="True" onrowdeleting="GridView1_RowDeleting" 
                onrowcommand="GridView1_RowCommand">
              <Columns>
                  <asp:BoundField DataField="region" HeaderText="区域" ReadOnly="true" />
                 <asp:BoundField DataField="meetingtime" HeaderText="时间" />
                 <asp:BoundField DataField="city" HeaderText="城市" />
                 <asp:BoundField DataField="sumcount" HeaderText="总数" />
                 <asp:BoundField DataField="address" HeaderText="具体地址" />
                <%-- <asp:CommandField HeaderText="修改" ShowEditButton="true"  />--%>
                <asp:TemplateField  HeaderText="更新">
                    <ItemTemplate>
                         <a οnclick='alterLocation("<%#Eval("LocationID")%>");' href="#">更新</a>
                    </ItemTemplate>
                </asp:TemplateField>
                

                  <asp:TemplateField HeaderText="删除" ShowHeader="False">
                      <ItemTemplate>
                          <asp:LinkButton  ID="lkBtnDel" runat="server" CausesValidation="False" CommandArgument='<%#Eval("locationID")%>'  OnClientClick="return confirm('您确认要删除吗?');" CommandName="Delete" Text="Delete">删除</asp:LinkButton>
                      </ItemTemplate>
                  </asp:TemplateField>

                    <asp:TemplateField HeaderText="发布" ShowHeader="False">
                      <ItemTemplate>
                          <asp:LinkButton  ID="lkBtnPublish" runat="server" CausesValidation="False" CommandArgument='<%#Eval("locationID")%>'  CommandName="Publish" Text='<%# GetStr(DataBinder.Eval(Container.DataItem, "IsPublish").ToString()) %>' ></asp:LinkButton>
                      </ItemTemplate>
                  </asp:TemplateField>
              </Columns>

          <HeaderStyle Height="25px" Font-Bold="false" BackColor="#dce4ec" />
            <RowStyle Height="25px" BackColor="#FFFFFF" />
            <FooterStyle Height="25px" />
           </asp:GridView>

 

后台:

 public string GetStr(string str)
    {
        if (str == "1")
        {
            return "取消发布";
        }
        else
        {
            return "发布";
        }
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string locationID = e.CommandArgument.ToString();
        Location location = dal.FindLocationByLoID1(locationID);
        GridViewRow row = ((Control)e.CommandSource).NamingContainer as GridViewRow;
        LinkButton lkbtn = (LinkButton)row.FindControl("lkBtnPublish");
        switch (e.CommandName)
        {
            case "Publish":
                {
                    if (lkbtn.Text == "发布")
                    {
                        location.IsPublish = "1";
                        dal.UpdateLocation(location);
                        Response.Redirect("LocationList.aspx?courseID="+courseID);
                    }
                    else
                    {
                        location.IsPublish = "0";
                        dal.UpdateLocation(location);
                        Response.Redirect("LocationList.aspx?courseID=" + courseID);
                    }
                    break;
                }
        }
    }


 


                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值