Click here to Skip to main content
15,888,218 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Comments
[no name] 23-May-14 9:04am    
Okay and what is the problem? Where is the code that demonstrates your problem? Get any errors? What errors do you get? On what line of code do you get these errors?
What's the issue?

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.

C#
// 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;
    }
  } 
} 
 
Share this answer
 
v2
I would suggest you to write your logic in RowDataBound event of the GridView control as follows:

C#
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900