Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

To Dynamically code delete button in Datagrid not to display if

Status
Not open for further replies.

ASPNETnewbie

Programmer
May 9, 2006
93
US
I was wondering how I would handle a situation where I have an imagebutton in my Datagrid code for my Delete button not to display if the status of information being displayed is true. How do I handle this If I already have my Delete button stored in the Datagrid template?

AspNEtNewbie

 
Use the ItemDataBound event. In there you can check if a condition exists and set the visible property of the imiage button accordingly.
 
hey,

I used the information you provided me and I know you are right about how I need to work this but I don't seem to be getting it right.

what I have is this
Code:
protected void FormatDelButton(Object sender, RepeaterItemEventArgs e)
{
     if( (e.Item.ItemType == ListItemType.Item) 
     {
     string x=(String)e.Item.DataItem;
     if( Convert.ToString(DataBinder.Eval(x, "Moved")) == "USA" )
         ((Label)e.Item.FindControl("btnDelete")).visible = false;
         ((Label)e.Item.FindControl("btnDelete")).enabled = false;
     }          
}

basically what I want it to do is check the extra property of what is sent to the column and if the extra property is set to MOVED, I need it not to display the imagebutton in that particular column. Can you help with more information on how exactly I can handle this?

AspNet
 
I don't know C# so my syntax may be off.. but something like this...
Code:
if (e.Item.ItemType == ListItemType.EditItem | e.Item.ItemType == ListItemType.AlternatingItem) { 
   DataRowView dr; 
   private object dr = ((DataRowView)(e.Item.DataItem));

   if dr.Item("Your Column" == "Moved") { 
      'Hide your Button code here..
   }
}
 
thanks.

I finally figured out the logic for the code but I seem to be having one problem. I would like to shut off the particular control which is itself contained in an Itemtemplate
Code:
<asp:TemplateField HeaderText="Rollover">
        <ItemTemplate>
       <asp:ImageButton ID="DeleteThis" runat="server" 
        ImageUrl="~/Images/Delete.gif"
     CommandName="DeleteMove" CommandArgument='<%# Eval("MoveID") %>' CausesValidation="false" />
</ItemTemplate>
[\code]

This is my code so far, however the lines 
[code]
((ImageButton)e.Item.FindControl("DeleteThis")).Visible = false;
((ImageButton)e.Item.FindControl("DeleteThis")).Enabled = false;

for some reason do not work at all.... Do I have it wrong?

Below is what I have
Code:
//OnItemDatabound event 
protected void FormatDeleteButton(Object sender, CommandEventArgs e)
{
string args;
int moveID = -1;

if(null != e.CommandArgument)
        {
            args = e.CommandArgument.ToString();
            if (DataValidation.IsInteger(args))
            {
                moveID = int.Parse(args);
            }
        }
        
        Movethis move;
        bool isBound;
        move = move.GetMove(moveID);
        
        isBound = (move.Status == moveType.Done || move.Status == moveType.Worked);
    
     if (e.CommandName == "DeleteQuote")&&
     {//disable the button itself if isBound evaluates to true
        ((ImageButton)e.Item.FindControl("DeleteThis")).Visible = false;
        ((ImageButton)e.Item.FindControl("DeleteThis")).Enabled = false;
     }
     
 }
[code
 
Nothing happens... I mean intellisense does not even pick up on e.item in the code behind


AspNetNewbie
 
I finally figured the problem out. For some reason I was not using the right DLL or something. But it worked out great, thanks for your help @Benson

Thanks a Whole lot

ASpNEt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top