gridview显示问题 [英] gridview display issue

查看:75
本文介绍了gridview显示问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望以这种方式在gridview中显示数据。如果staus处于挂起状态,则该行显示数据显示暂停禁用打印图像按钮或隐藏该行

gridview动态填充数据库

i want display data in gridview in such way .if staus is signed dispaly print image button of that row if staus is pending disable print image button or hide of that row
gridview is filling dynamically from database

推荐答案

您必须在gridview的 RowDataBound 事件处理程序中编写代码以检查记录的状态,并相应地使打印图标启用或禁用特定行。请在下面查看类似示例。



You have to write code in RowDataBound event handler of gridview to check the status of record and accordingly make print icon enable or disable of particular row. Please check below the similar example.

// The event handler of RowDataBound event of gridview. Please make sure that this event should be called in defination of gridview in source. 
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
// Here we check that row should be a datarow not a header or footer
  if (e.Row.RowType == DataControlRowType.DataRow) 
  { 
// Here we find the imagecontrol (print icon) and hiddenfield (status). Make sure that you added these controls in ItemTemplate or AlternateItemTemplate of gridview and assign the status of record in hiddenfield..
    ImageButton imgPrint = (ImageButton )e.Row.FindControl("PrintImageButtonName"); 
    HiddenField hdnStatus = ((HiddenField)e.Row.FindControl("StatusHiddenFieldName")); 

// Here we check for the status of record and enable/disable imagebutton accordingly.
    if(hdnStatus.Value.ToLower()=="signed")
    {
      imgPrint.Enabled=true;
    }
    else
    {
      imgPrint.Enabled=false;
    }
  } 
} 


我建​​议你在 RowDataBound 中写下你的逻辑GridView控件的事件如下:



I would suggest you to write your logic in RowDataBound event of the GridView control as follows:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ImageButton btnPrint = (ImageButton)e.Row.FindControl("btnPrint");
                string status = e.Row.Cells[3].Text;
                if (status == "signed")
                {
                    btnPrint.Visible = true;
                }
                else
                {
                    btnPrint.Visible = false;
                }
            }
        }





这里我假设数据源的第三列具有状态值(即签名/待定)。



如果您需要完整的代码,请告诉我。



Here I'm assuming that third column of the data source having the status value (i.e. signed / pending).

Please let me know in case you need the complete code.


这篇关于gridview显示问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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