如何禁用 ASP.NET 中单个列的 ItemTemplate 内的项目

发布于 2024-12-11 17:46:01 字数 2131 浏览 0 评论 0原文

 <Columns>
                        <asp:TemplateField HeaderText="Actions" ItemStyle-Width="15%">
                            <ItemTemplate>
                                <asp:ImageButton ID="imgbtn" ImageUrl="Styles/Images/Edit.jpg" runat="server" Width="25"
                                    Height="25" OnClick="imgbtn_MessageEditClick" Enabled="True" ToolTip="Edit Message" />
                                <asp:LinkButton ID="Lnk_Delete"  CommandArgument='<%# Eval("MsgID") %>'
                                    CommandName="Delete" runat="server" >                                        <img id="Img1" src="Styles/Images/Delete.jpg" runat="server" style="border-style: none"
                                        alt="Delete Message" /></asp:LinkButton>
                                <asp:ImageButton ID="imgbtn_ViewDashBoard" ImageUrl="Styles/Images/dash.jpg" Enabled="True"
                                    Width="" runat="server" PostBackUrl='<%# Eval("MsgID", "ResponseMetric.aspx?MsgID={0}") %>'
                                    Text='Send' ToolTip="View DashBoard"></asp:ImageButton>
                            </ItemTemplate>

我有这些项目模板,它们位于同一列中,我有另一列 MessageActive。在 rowDataBound 中,如果 messageActive 为 no,则我将行颜色设置为红色,对于同一列,如何禁用 ImageButton ID="imgbtn"< /code> 和 ItemTemplate 内的 asp:LinkBut​​ton ID="Lnk_Delete"

protected void MyGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        System.Web.UI.WebControls.Image img = (System.Web.UI.WebControls.Image)e.Row.FindControl("Status");
        int msgid;
        int.TryParse(Convert.ToString(DataBinder.Eval(e.Row.DataItem, "MsgID")), out msgid);            
        string status = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "MessageActive"));
        if(status.Equals("No"))
        {
            e.Row.BackColor = Color.Red;

        } 
      }
    }

我为 gridview 进行databind

 <Columns>
                        <asp:TemplateField HeaderText="Actions" ItemStyle-Width="15%">
                            <ItemTemplate>
                                <asp:ImageButton ID="imgbtn" ImageUrl="Styles/Images/Edit.jpg" runat="server" Width="25"
                                    Height="25" OnClick="imgbtn_MessageEditClick" Enabled="True" ToolTip="Edit Message" />
                                <asp:LinkButton ID="Lnk_Delete"  CommandArgument='<%# Eval("MsgID") %>'
                                    CommandName="Delete" runat="server" >                                        <img id="Img1" src="Styles/Images/Delete.jpg" runat="server" style="border-style: none"
                                        alt="Delete Message" /></asp:LinkButton>
                                <asp:ImageButton ID="imgbtn_ViewDashBoard" ImageUrl="Styles/Images/dash.jpg" Enabled="True"
                                    Width="" runat="server" PostBackUrl='<%# Eval("MsgID", "ResponseMetric.aspx?MsgID={0}") %>'
                                    Text='Send' ToolTip="View DashBoard"></asp:ImageButton>
                            </ItemTemplate>

I have these Items templates, which is in the same column, I have another column MessageActive. In the rowDataBound if the messageActive is no then I set the row color to red, and for the same column how can I disable ImageButton ID="imgbtn" and asp:LinkButton ID="Lnk_Delete" inside the ItemTemplate.

protected void MyGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        System.Web.UI.WebControls.Image img = (System.Web.UI.WebControls.Image)e.Row.FindControl("Status");
        int msgid;
        int.TryParse(Convert.ToString(DataBinder.Eval(e.Row.DataItem, "MsgID")), out msgid);            
        string status = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "MessageActive"));
        if(status.Equals("No"))
        {
            e.Row.BackColor = Color.Red;

        } 
      }
    }

I do databind for the gridview.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

想念有你 2024-12-18 17:46:01
ImageButton btnEdit = (ImageButton)e.Row.FindControl("imgbtn");
btnEdit.Enabled = !status.Equals("No");
LinkButton btnDelete = (LinkButton)e.Row.FindControl("Lnk_Delete");
btnDelete.Enabled = !status.Equals("No");
ImageButton btnEdit = (ImageButton)e.Row.FindControl("imgbtn");
btnEdit.Enabled = !status.Equals("No");
LinkButton btnDelete = (LinkButton)e.Row.FindControl("Lnk_Delete");
btnDelete.Enabled = !status.Equals("No");
情深如许 2024-12-18 17:46:01

您可以将以下代码添加到 RowDataBound 事件处理程序方法中

    ImageButton imgBtn = e.Row.FindControl("imgbtn") as ImageButton;
    LinkButton lnkBtn = e.Row.FindControl("Lnk_Delete") as LinkButton;


    if (null != imgBtn)
        imgBtn.Enabled = false;

    if (null != lnkBtn)
        lnkBtn.Enabled = false;

you can add the following code to your RowDataBound event handler method

    ImageButton imgBtn = e.Row.FindControl("imgbtn") as ImageButton;
    LinkButton lnkBtn = e.Row.FindControl("Lnk_Delete") as LinkButton;


    if (null != imgBtn)
        imgBtn.Enabled = false;

    if (null != lnkBtn)
        lnkBtn.Enabled = false;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文