Category Archives: DetailsView

[RESOLVED] How to programtically set template fields label value two one of two fields returned in a sqldatasource

 I have a sql data souce that returns several columns of data, and they are displayed in a DetailsView on a pretty simple vb.net page.  I'm stuggling with one field though for the details view.  It's a template field, and if ClientType=1 (this value is determined else where on the page), then the label in the template field should have Text='<%# Bind("ClientName") %>', but if the ClientType = 0, then the label in the template field should have Text='<%# Bind("ClientTemporaryName") %>'

How do I tell the details view to set the text for ClientName to one or the other? 

<asp:TemplateField HeaderText="Client" SortExpression="ClientName">
<ItemTemplate>
<asp:Label ID="lblClientNameForSummary" runat="server" Text='?????'></asp:Label>
</ItemTemplate>
</asp:TemplateField>


 

I would personally put that logic into a SQL view so you only have to show one field in the label.  Otherwise, you will need to loop through each item in the DetailsView and update the text field from your code-behind.

 

Matt

I would put the logic in my SQL SELECT statement, with something like this:

SELECT ClientType,
 Case When ClientType = 0 Then ClientTemporaryName
      When ClientType = 1 Then ClientName
 END AS ClientNameForSummary
FROM  Clients

Then bind your lblClientNameForSummary with this: Text='<%# Bind("ClientNameForSummary") %>'

SELECT CASE is my new best friend... slightly behind ISNull!

Thank you..  So simple now.   

[RESOLVED] detailsview control validation

In vb.net web page i have textbox control , button control  and detailsview,when button is clicked textbox.text is searched in database and data is dispayed in a listbox  then the selectedvalue of the listbox is put in detailsview ,all this is fine but it dosen't work like that when I click the button the detailsview validated fields are red and nothing work until I fill the all datailsview's fields, so I want to know how to stop detailsview validations till I get the listbox selected value and put it in one of the detailsvalue's filed.

You can either set CausesValidation="false" for the button

or

specify same validationGroup such as ValidationGroup="Search" for both search Textbox and button. That should not fire DetailsView validations when left blank.

Thank you indeed I used causevalidation="false" to the button and it worked fine ,thank you again.

 

[RESOLVED] Disable a Image button or Hyperlink button based on ASP.Net Role

Ok, here's my issue I have four Imagebuttons that I want to disable depending on the Role the user belongs too.  I know how do do this in a gridview or detailsview but for some reason it isn't working on just a plain form.

So when a User who is not in the "Admin" role logs onto the page he either doesn't see  the button or the hyperlink has been disabled thus not allowing him to proceed any further.

 

Anyone got any ideas?

 

Any assistance would be greatly welcomed.

Here is an example that i would use:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            If Not User.IsInRole("Admin") Then
                Image1.Visible = False
            End If
        End If
    End Sub


 

or in c#:

protected void Page_Load(object sender, System.EventArgs e)
{
	if (!Page.IsPostBack) {
		if (!User.IsInRole("Admin")) {
			ImageButton1.Visible = false;
                        hyperlink1.visible = false;
		}
	}
}


 

Well that seemed to take care of it for the most part.  I do have 1 issue still, I actually have 4 Roles (Admin, Supervisor, PowerUser, User).  I can get each to work individually from each other is there a way that I could do something like this:

If not Page.IsPostBack then
If Not User.IsInRole("Admin") or (User.IsInRole("Supv") then
Image1.visible = false
End if
end if


  

 you can do this:

Protected Sub Page_Load(sender As Object, e As System.EventArgs)
	If Not Page.IsPostBack Then
		If (Not User.IsInRole("Admin")) OrElse (Not User.IsInRole("Supv")) Then
			ImageButton1.Visible = False
			hyperlink1.visible = False
		End If
	End If
End Sub


 

that doesn't seem to work at all, nothing is showing up.

Here's the code based of your sample:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            If (Not User.IsInRole("Admin")) OrElse (Not User.IsInRole("GADS")) Then
                GADSItemButton.Visible = False
            End If
        End If
    End Sub


Any Ideas why this isn't working.  And "yes", GADS is a role.

 

I figured it out.  Thanks 

Did you check: there are any links/image for 'Admin' or 'GADS' role ? and also debug the code to see what it's actually returning....

[RESOLVED] Gridview getting out of synch with source data

The Patient Scheduling system I have built extracts current inpatient data from an enterprise health system and merges it with data from a seperate database, based on a common key. This is then displayed in a gridview control for browse/update.

At any one point in time, the client list in my system should reflect the current inpatients in the enterprise system.
The problem is that if the user has not refreshed the client list in some time, there may have been a discharge in the enterprise system and the two get out of synch. When the user selects a client from the list to update, the details of an entirely different client (usually the one below), is presented in edit mode. e.g. if the user selects  the 4th client in the list, the details for the 5th client are made available for update. 

Any thoughts on how I can get around this.

One option would be to not edit within the GridView itself, and use the DetailsView / FormView combination (with or without a ModalPopupExtender if you will, to make it "user-friendly").
But that will ensure the GridView doesn't bind over its data source again. You would use the RowCommand or SelectedIndexChanged events.
Even though the details might load with changes, IF any applied by someone else in the meantime, which might be quite different to those displayed in the GridView row.

 

Another option might be to find the RowIndex that matches the value by ID (DataKeys) chosen to be edited (besides, this might be on anther page entirely). 

 

 

Madog

e.g. if the user selects  the 4th client in the list, the details for the 5th client are made available for update. 

looks like, in the meantime, somebody else deleted a record

 

Madog

The problem is that if the user has not refreshed the client list in some time,

I think it's a tall order to expect the GridView to take responsibility to sync-up over such unusually long time periods (or any other control for that matter).

(You could have your users refresh the GridView if they've been away too long! ;))

Thanks for your replies.

I understand its not the gv's fault, but just require a workaround. The gv is contained within an AJAX udpatepanel, so the approach I am taking at the moment is to assess the performance impact of databinding the gv on a regular interval using a timer.

If that doesn't work out, I plan to extract the key field in rowcommand (which takes place before rebinding over the datasource), and compare it to the key field on rowupdating (or perhaps preRender), and cancel the update if they are different, throwing a message box to the user.