如何通过网格行选择启用/禁用按钮 [英] How to enable/ disable button through grid row selection

查看:91
本文介绍了如何通过网格行选择启用/禁用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个带有各种列的网格.例如.网格具有状态列.我想根据状态(选择的特定行)启用/禁用按钮(编辑按钮,取消按钮).它们也是网格中的其他列.

Hi All,

I have a Grid with various columns. For eg. Grid havng a column with status. I want to enable / disable the buttons(edit button, cancel button) as per the status (that particular row selected). their are other columns in grid as well.

<Button x:Name="btnEdit" Content="Edit" Style="{StaticResource GreyButtonStyle}" IsEnabled="{Binding EditEnable}" >
          <i:Interaction.Triggers>
            <i:EventTrigger EventName="Click">
              <cmd:EventToCommand Command="{Binding Path=EditCustomerOrdersCommand}" PassEventArgsToCommand="True" />
            </i:EventTrigger>
          </i:Interaction.Triggers>
        </Button> <DataGrid:GridViewDataColumn DataMemberBinding="{Binding Status}" Header="Status" TextWrapping="NoWrap" Width="*" />


我''使用MVVM模式进行开发.

请帮帮我.

在此先感谢.


I'' using MVVM Pattern for my development.

Please help me.

Thanks in Advance.

推荐答案

您好,我将使用网格的RowDataBound方法.分析数据,然后根据需要禁用控件.

网格代码:
Hi, i would use the RowDataBound method of the grid. Analize your data and then disable the control as you wish.

Grid Code:
<asp:gridview id="GridView1" runat="server" xmlns:asp="#unknown">
           onrowdatabound="GridView1_RowDataBound">
           <columns>
               <asp:boundfield datafield="Name" headertext="Name" />
               <asp:commandfield showeditbutton="True" />
           </columns>
       </asp:gridview>



背后的代码



Code Behind

protected void Page_Load(object sender, EventArgs e)
        {
//Fill th DataSource

            DataTable tbl = new DataTable("data");
            tbl.Columns.Add("Name");
            DataRow row = tbl.NewRow();
            row["Name"] = "Luis";
            DataRow row2 = tbl.NewRow();
            row2["Name"] = "Carl";
            
            tbl.Rows.Add(row);
            tbl.Rows.Add(row2);

//Bind the grid
            this.GridView1.DataSource = tbl;
            this.GridView1.DataBind();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
//Disable the control
                if (((System.Data.DataRowView)(e.Row.DataItem)).Row[0].Equals("Luis"))
                {
                    ((WebControl)((System.Web.UI.WebControls.TableRow)(e.Row)).Cells[1].Controls[0]).Enabled = false;
                    
                }
            }
        }




希望对您有帮助.问候.




I hope it help you. Regards.


这篇关于如何通过网格行选择启用/禁用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆