telerik grid edit with validators seems overlapped - asp.net

i have a telerik grid for asp.net ajax with AllowAutomaticxxxx properties set to true and EditMode="EditForms".
The mastertableview is for Divisions and detail table is for functions. Currently am able to insert new division and function and also edit division and function. i am using required field validator for both divisions and functions. now am facing a problem. the validator appears as overlapped when opening one edit function and one insert division.i mean when they are opened at the same time, and when i edited the function and clicked the update button, the validator for division name appears!!
1 more thing i have used ajaxmanager for the grid and i am not sure whether this is the issue.

i solved this issue by setting validationgroup for each edit and delete like this in the itemCreated event of the grid
If TypeOf e.Item Is Telerik.Web.UI.GridEditableItem AndAlso e.Item.IsInEditMode Then
If "Divisions".Equals(e.Item.OwnerTableView.Name) Then
Dim rvDivisionName = DirectCast(e.Item.FindControl("rvDivisionName"), RequiredFieldValidator)
If TypeOf e.Item Is Telerik.Web.UI.GridEditFormInsertItem Then
rvDivisionName.ValidationGroup = "addDivisionRowValidation"
TryCast(TryCast(e.Item, Telerik.Web.UI.GridEditFormItem).FindControl("PerformInsertButton"), LinkButton).ValidationGroup = "addDivisionRowValidation"
Else
rvDivisionName.ValidationGroup = "editDivisionRowValidation"
TryCast(TryCast(e.Item, Telerik.Web.UI.GridEditFormItem).FindControl("UpdateButton"), LinkButton).ValidationGroup = "editDivisionRowValidation"
End If
ElseIf "Functions".Equals(e.Item.OwnerTableView.Name) Then
Dim rvFunctionName = DirectCast(e.Item.FindControl("rvFunctionName"), RequiredFieldValidator)
Dim rvFunctionRoleName = DirectCast(e.Item.FindControl("rvFunctionRoleName"), RequiredFieldValidator)
If TypeOf e.Item Is Telerik.Web.UI.GridEditFormInsertItem Then
rvFunctionName.ValidationGroup = "addFunctionRowValidation"
rvFunctionRoleName.ValidationGroup = "addFunctionRowValidation"
TryCast(TryCast(e.Item, Telerik.Web.UI.GridEditFormItem).FindControl("PerformInsertButton"), LinkButton).ValidationGroup = "addFunctionRowValidation"
Else
rvFunctionName.ValidationGroup = "editFunctionRowValidation"
rvFunctionRoleName.ValidationGroup = "editFunctionRowValidation"
TryCast(TryCast(e.Item, Telerik.Web.UI.GridEditFormItem).FindControl("UpdateButton"), LinkButton).ValidationGroup = "editFunctionRowValidation"
End If
End If
End If

Related

Can't get a checkbox value inside a gridviewrow controls

i programatically populate a gridview with checkbox like this
Dim checkbox As New CheckBox()
checkbox.Checked = True
checkbox.ID = String.Format("chkChecked{0}", i)
MyRow.Cells(i).Controls.Add(checkbox)
later on i tried to access them with this
Dim chk As CheckBox = DirectCast( Row.FindControl(String.Format("chkChecked{0}", i)),CheckBox)
over the row but it does'nt work, any idea of what is going on? thank in advance
I use this code to access CheckBox control inside CellContentClick or CellClick events of the DataGridView :
Dim CheckBox As DataGridViewCheckBoxCell = CType(grdDataGridView.CurrentCell, DataGridViewCheckBoxCell)
If you want you can replace grdDataGridView.CurrentCell with grdDataGridView(columnIndex,rowIndex).
At the end I use EditedFormattedValue to check the value of the CheckBox.
If (CheckBox.EditedFormattedValue) Then
....
End If
Let me know if you need more help.
Regrads,
Boris

How can I add a hyperlink to a dropdownlist create in vb.net code behind?

I create a dropdownlist in code behind with this:
Public sub CreateDDL()
Dim ddl As New DropDownList
Dim list As ListItem = New ListItem()
list.Text = "printTemplate1"
list.value = "~/template1.aspx"
ddl.Items.Add(list)
End Sub
I don't know how to put the value to be a link.
Suggest me, thanks.
I solve my problem at this way :
Public sub CreateDDL()
Dim ddl As New DropDownList
' ############# THE MODIFICATION ########################
ddl.Attributes.Add("onchange", "template1.aspx")
' ##################################################
Dim list As ListItem = New ListItem()
list.Text = "printTemplate1"
ddl.Items.Add(list)
End Sub
I hope it will be helpful to someone
What you are looking for is quite not possible because DropDownList render themselves into native HTML select. These controls aren't really designed to do such kind of activity.
In order to make them navigate to other page you need to combine them with client side script and make them behave as per your requirement. For E.g.
$(function() {
$("#<%=ddl.ClientID%>").change(function(e) {
var selectedUrl = $(this).val();
window.location.href = selectedUrl;
});
});
Also you can make use of ResolveURL() or ResolveClientUrl() to create a relative path to the root or relative to the current page respectively and then assign them to the ddl value.
list.value = ResolveUrl("~/template1.aspx");
/*or*/
list.value = ResolveClientUrl("~/template1.aspx");

ASP.Net - Reducing repetitive code for validation - VB

I have a form with many drop down list boxes on. Each of which I am showing or hiding a row of a table based on its value then adding a requiredfieldvalidator to the text box contained in that row. I am doing this on the selectedindexchanged event of each drop down list, the code for which can be seen below:
Protected Sub cbOffCover_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbOffCover.SelectedIndexChanged
If cbOffCover.SelectedValue = "N" Then
OffCoverRow.Visible = True
Dim rfOffcover As RequiredFieldValidator = New RequiredFieldValidator
With rfOffcover
.ControlToValidate = txtOffCover.ID
.SetFocusOnError = True
.ErrorMessage = "*"
.ForeColor = System.Drawing.Color.Red
End With
OffCoverCell.Controls.Add(rfOffcover)
Else
OffCoverRow.Visible = False
Dim c As Control
For Each c In OffCoverCell.Controls
If c.ID = "rfOffCover" Then
OffCoverCell.Controls.Remove(c)
End If
Next c
End If
End Sub
I then reuse this code for each drop down list to show/hide a differently named row and apply validation to a different text box.
My question being is there a better way of doing this? I don't know exactly how but I can't help but think I don't have to write this much code (or copy/paste) over and over again for each drop down list. Is it possible to write a function/class that will do the work and I can just call that instead? Might seem basic but i'm new to asp/vb. Many thanks
You can put it in a function that returns a boolean. When you call the function, pass it the combobox itself and whatever values you want to validate against. If it matches, return true. Try something like this:
Public Function ValidateComboBox(someComboBox as ComboBox, expectedValue as String)
Dim result as Boolean = False
If someComboBox.SelectedValue = expectedValue Then
result = True
OffCoverRow.Visible = True
Dim rfOffcover As RequiredFieldValidator = New RequiredFieldValidator
With rfOffcover
.ControlToValidate = txtOffCover.ID
.SetFocusOnError = True
.ErrorMessage = "*"
.ForeColor = System.Drawing.Color.Red
End With
OffCoverCell.Controls.Add(rfOffcover)
Else
OffCoverRow.Visible = False
Dim c As Control
For Each c In OffCoverCell.Controls
If c.ID = "rfOffCover" Then
OffCoverCell.Controls.Remove(c)
End If
Next c
End If
Return result
End Function
Of course, modify it to fit your needs. Maybe you only return the value, and do the other stuff inside the control's SelectedIndexChanged method.

Creating a New control of the same type as another control that is already declared

I'm using a custom template class to generate lines with my repeater control, i'd like to be able to specify the controls in this repeater dynamically from the code behind my aspx page.
In the code behind I've added controls to a list like this:
Dim lstControls As New List(Of Control)
lstControls.Add(New TextBox)
lstControls.Add(New Label)
lstControls.Add(New CheckBox)
lstControls.Add(New DropDownList)
lstControls.Add(New CheckBox)
Then i use this line to add the controls to my template
rptrSummary.ItemTemplate = New myTemplate(ListItemType.Item, , lstControls)
From the instantiateIn sub i'm doing something like this:
Dim ph As New PlaceHolder
For i = 0 To lstControls.Count - 1
ph.Controls.Add(lstControls(i))
Next
This doesn't work properly and following .databind() of my repeater control the controls i specify only appear on the final row. I think this is because i've only declared the controls as NEW once, so i only have one rows worth.
tldr?/ conclusion:
How can i generate new controls of the same type as controls from my list? Something like:
Dim newControl as new Control = type(lstControl(0))
(this obviously doesn't work)
I've found the answer, here are some examples in case anyone else is stuck (i may also change the title so it's more similar to likely search criteria):
dim egTextbox as new textbox
dim egLabel as new label
dim newObject1 as Object = Activator.CreateInstance(egTextbox.GetType)
dim newObject2 as Object = Activator.CreateInstance(egLabel.GetType)
newObject1 is now a textbox
newObject2 is now a label

showing images dependent on check box value

I am using a DataGrid, in VB, I have a check box. If it is checked I turn image.visible to true. This is done within the ItemDataBound method. How can I get it so when the check box status is changed, the DataGrid is rebound and uses the if statement to decide whether to show the images or not?
my code in ItemDataBound is:
Dim img As Image = e.Item.FindControl("pImage")
'Find the current Part
Dim qJob As qJob = CType(e.Item.DataItem, qJob)
Dim currentJob As New Job(qJob.JobCode)
img.ImageUrl = "~/ImageShow.aspx?JobID=" + JobID.ToString + "&Height=300&Width=300"
'Find the control and whether that part has an image, if there is an image, display the preview button
If currentJob.JObImage IsNot Nothing AndAlso checkShowImages.Checked = True Then
img.Visible = True
End If
When the checkbox status is changed how can I update the datagrid?
thanks

Resources