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 があります。rowDataBoundmessageActive が noの場合disable ImageButton ID="imgbtn"、行の色を赤に設定し、同じ列asp:LinkButton ID="Lnk_Delete"に対して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;

        } 
      }
    }

私はdatabindのために行いgridviewます。

4

2 に答える 2

3
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");
于 2011-10-24T13:36:20.937 に答える
1

次のコードを 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;
于 2011-10-24T13:40:55.937 に答える