天天看點

GridView中使用LinkButton按鈕(工作心得)

GridView中使用LinkButton按鈕(工作心得)  

  前台代碼: < asp:TemplateField HeaderText="稽核">

               <ItemTemplate>

                   <asp:LinkButton ID="lbCharge" runat="server" CommandName="charge" OnClientClick="if(!confirm('确認通過稽核嗎?')) return false"><font color=red>通過</font></asp:LinkButton>

                    <asp:LinkButton ID="lbDelete" runat="server" CommandName="del"

                                        OnClientClick="if(!confirm('确認取消稽核嗎?')) return false">取消</asp:LinkButton>

                                </ItemTemplate>                        

            </asp:TemplateField>

                  <asp:BoundField DataField="news_IsLock" HeaderText="稽核" /> 背景代碼:

protected void GridView_NewsList_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        if (e.Row.RowType == DataControlRowType.DataRow)

        {

            //**************滑鼠放上去顯高亮

            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#CFE4EF'");

            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#E0EEF5'");         

            //**************結束

            LinkButton lbDelete = (LinkButton)e.Row.FindControl("lbDelete");

            lbDelete.CommandArgument = e.Row.RowIndex.ToString();

            LinkButton lbCharge = (LinkButton)e.Row.FindControl("lbCharge");

            lbCharge.CommandArgument = e.Row.RowIndex.ToString();

            if (e.Row.Cells[6].Text == "True")

            {

                //e.Row.Cells[6].Text = "已稽核";

                //e.Row.Cells[6].ForeColor = System.Drawing.Color.Red;

                lbDelete.Visible = true;

                lbCharge.Visible = false;

                e.Row.Cells[6].Visible = false;

            }

            else

            {

                //e.Row.Cells[6].Text = "未稽核";

                lbDelete.Visible = false;

                lbCharge.Visible = true;

                e.Row.Cells[6].Visible = false;

            }

        }

        if (e.Row.RowType == DataControlRowType.Header)

        {

            e.Row.Cells[6].Visible = false;

        }

    }

    protected void GridView_NewsList_RowCommand(object sender, GridViewCommandEventArgs e)

    {

        int index = int.Parse(e.CommandArgument.ToString());

        DataKey key = this.GridView_NewsList.DataKeys[index];

        Int64 payid = Int64.Parse(key.Value.ToString());

        switch (e.CommandName)

        {

            case "charge":

                {

                    //string mysql = "update News set fd_IsLock=1 where fd_Id=" + payid;

                    //Conn.ExecuteSql(mysql);

                    FdNews.CloseLockNews(payid);

                    BindGrid();

                    break;

                }

            case "del":

                {

                    //string mysql = "update News set fd_IsLock=0 where fd_Id=" + payid;

                    //Conn.ExecuteSql(mysql);

                    FdNews.OpenLockNews(payid);

                    BindGrid();

                    break;

                }

        }

    }

轉載于:https://www.cnblogs.com/bluedy1229/articles/1282973.html