Forms Data Controls :: Conditionally Hide 2 LinkButtons In A Grigview?
Aug 26, 2010
I'm trying to conditionally hide 2 link buttons within a Gridview(gvPosts), ModifyButton and DeleteButton. I want the two buttons to hide in every row where the currently logged on Username is not the same as the Username in gvPosts' lbEmpID, a LinkButton control in the same row. Unfortunately the code is hiding the buttons in every row, including the one where lbEmpID.text = Profile.Username. My code is below, what am I doing wrong?
Dim lbtn As LinkButton
For Each rowItem As GridViewRow In gvPosts.Rows
lbtn = DirectCast(rowItem.Cells(0).FindControl("lbEmpID"), LinkButton)
If lbtn.Text <> Profile.UserName Then
Dim Modify As LinkButton
Dim Remove As LinkButton
For Each rowItem1 As GridViewRow In gvPosts.Rows
Modify = DirectCast(rowItem1.Cells(0).FindControl("ModifyButton"), LinkButton)
Remove = DirectCast(rowItem1.Cells(0).FindControl("RemoveButton"), LinkButton)
Modify.Visible = False
Remove.Visible = False
Next
End If
'If chk.Checked Then
'Response.Write(chk.ClientID + "<br />")
'End If
Next
Then I am adding boundfield to gridview for all 4 columns. Now I want to check if "Type" column contain "Sales" thne do not show "Manager" columns. Let me know can I do this?
On Row databound i want to show some rows in If and Hide in some rows in else conditon. But it generate an exception that (Index was out of range. Must be non-negative and less than the size of the collection Parameter name: index.
protected void gvHotels_RowDataBound(object sender, GridViewRowEventArgs e) { DataTable dt = new DataTable(); if (e.Row.RowType == DataControlRowType.DataRow)
I am working on an app where i am having some linkbuttons in master page. I want to display them depending upon the authorization given to them once they logs in. I have initially made all of them visible false and then i am checking the authorisation in the aspx.cs class of master page. I make the link button visible depending upon the right granted to the user. But it is making all the link buttons visible. Instead it should only make two of them visible and rest should be hidden. Following is my code from MasterPage.aspx.cs:
I have a page with a label and a textbox with two button edit and update. when the user clicks on edit the labels get hidden and text box appears. And when he clicks on update the textbox disappears and label appears I have achieved making the text box disappear and label appear but when I click on edit the textbox is not appearing ....
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Institute : System.Web.UI.Page {
I am working in MVC & using MVCContrib grid to my results in grid format.
Along with all columns in resultant grid i have added a actionlink button "Delete", which i want not to show with some default record entry i.e., delete link should not show in a row which has code=000.
im showing 3 rows and 2 columns in a Gridview...I want to generate a 3rd column at runtime in a Gridview ....
only 1 LinkButton in Gridview at position row1 and column 3 only 2 LinkButton in Gridview at position row2 and column 3 only 3 LinkButton in Gridview at position row3 and column 3
I have a GridView attached to an ObjectDataSource (returning a DataTable) in a UserControl. The code is really simple. Data comes down fine when the page is first rendered. When I click on Select or Delete (inside TemplateFields), RowCommand is supposed to fire but it doesn't, the page goes straight to Page_Load. I literally have 0 other event handlers that are set on this control and everything else in the codebehind shouldn't even fire if it's a postback. Also on postback, the Select and Delete buttons disappear. It looks like the TemplateFields are still there but they're empty. The data fields (all of two columns) post back fine.
I have a GridView in an update panel that is bound (in code-behind) to a business layer object. The first time this page is accessed, Editing, Deleting, Updating, etc. work fine. However, if I click my browser's refresh button, the functionality of the edit, delete, etc link buttons is gone. They do nothing.
I've got this gridview with a column labeled "Client Comment" that displays a clickable little icon when there is a client comment in the database. The problem is the icon is appearing whether or not there is data in the DB (except I don' t think it does when the DB value is null.)
How can I make it so the icon only appears if there is a comment in that database field? With code behind (if so VB) or in the tag?
I am trying to delete row(s) from the DataTable conditionally but I cant.
Actually I have DataList with CheckBox (default value checked=false). I am bindind DataList at run time using DataView (Dataview is created fromDataTable).
I also have <asp:Button ID="btnDelete" ....> which I am using to delete checked items in the DataList (But this functionality is not working).
The user first "checked" items in the DataList and click the the button "btnDelete". Here nothing is being deleted (?) and the DataList appears with all the items"unchecked" (even those which the the "checked" by the user). protected void btnDelete_Click(object sender, EventArgs e) . In this function I am checking state of the checkbox before deleting the row in the DataTable.
On PostBack generated by the "btnDelete", DataList appears with checkboxes unchecked therefore nothing is being deleted
I'm modifying an existing application. I need to be able to bind the Text property of an asp:DropDownList control to one of two fields when the page is rendered. The existing code is like this:
[Code]....
I've tried to use conditional logic on the .aspx page when setting the Text property, but everything I've tried results in an error. I've also tried using code-behind to set the Tetxt property in the Page_Load event. This doesn't generate an error, but it doesn't set the property either.
using a repeater to display multiple 'comments' related to a parent database entity (a 'task' in my case). When the user creates these comments they can optionally attach a file. Now, I'm working on the page that lists these comments and I'm not sure how to go about displaying the link to the attached file, if one is present. There may not be a file. The database record that contains the comment will also contain the url to the file if one was attached.
what are my options for this? I would like to just display a link to the file after the comment content, only if a file is available.
using a listView control... I'm trying to use the ItemDataBound event to map a field's native value to a more 'friendly' name... so far I have the code to access the underlying data so the decision can be made for the actual mapping, but I don't know how to actually change the data displayed?
I am facing a situation where I have to disable GridView field (in EDIT mode ) conditionally.
Here is the situation,GridView has 5 fields "Product Name" "Small" " Medium" "Large" "XLarge"
Here is the problem, application has section where user activate/deactivate sizes (SMALL,MEDIUM,LARGE,XLARGE). Suppose User activates "SMALL" and "LARGE". Now When the GridView is populted normally, I don't have to disable any fields. But when the user clicks "EDIT" on GridView row, I want "MEDIUM" and "XLARGE" fields to appear as disable.
Here is what I know
1) I will have active sizes in SESSION ... in the above case (SMALL and LARGE)
2 I know I have to catch GridView_RowDataBound and then I have to check for the edit mode for the row.
I have created a gridview and added a headertemplate field inside templatefield. Inside header template field I have added a button and a condirmbutton extender. confirmbutton extender uses modelpopup with ok cancel. This works fine but with one problem. I want this popup to open on button click only if user has checked atleast one checkbox from gridview. So far it shows this modelpopup everytime even user hasn't checked anything.
For this I am using ASP.NET 4.5, C#, and Entity Framework to SQL.
I have some sections of my site where users can make multiple entries and can optionally upload attachments. There is a page where the user can see a gridview that acts as an overview of the entires. I have been asked to display a column with a paperclip icon if an attachment exists.
The way the database is structured, the table that holds the entries has columns like this:
The attachments are in another table. For this table the attachmentId will hold an Int32 or be NULL (no attachment). My current query looks like basically like this:
var query = context.applications.Where(c => c.id == applicationPrimaryKey); var results = result.educationUniversities.ToList(); gdvEducationUniversity.DataSource = results; gdvEducationUniversity.DataBind();
I somehow need to create a condition where an image of a paperclip is shown if the attachmentId value is not Null. Optionally I imagine the query could be re-written to return a true/false value based on if the attachmentId value is null though I'm not certain how to do this.