I've been trying out telerik's ajax controls and so far they haven't given me huge problems. I'm using their ajax radgrid with editing capabilities and one of their suggestions is to use a web forms user control (.ascx) filled programmatically with controls to edit a particular grid record.
I can open the web form just fine and also fill it in code-behind with the following controls:
- textboxes
- labels
- dropdownlists
For the grid I've been testing the edit functionality, to edit a record i need 3 dropdownlists in order to properly edit it, now this is where my problems start.
I have a function that adds records if they match certain metadata criteria, if I put a breakpoint in between adding the controls and do the following steps:
- add the first "line" of controls (label and textbox)
add the second "line" of controls (label and dropdownlist)
If i stop here and step into to end the function the following happens, both labels have the right text as well as the textbox but the dropdownlist not so much, even though I have set the selected index do value "2" and in quickwatch it stays at 2, once the web form is displayed the default value value resets to "0"
add the third "line" of controls (label and dropdownlist)
If i stop here and step into the end of the function, even though in quickwatch everything is fine, once the web form is displayed/loaded, both dropdownlists will have the same values inside them and they will both have their selectedindex = 0
edit:i'll describe the behaviour i'm expecting:
- the first dropdown(1) to be filled with for example "None,A,B,C,D,E,F,G" and have "A" as the selecteditem
- the second dropdown(2) to be filled with for example "None,F1,F2,F3,F4,F5,F6" and have "F3" as the selecteditem
this is behaviour i'm getting:
once the web form is loaded, dropdown(1) and dropdown(2) are filled with "None,F1,F2,F3,F4,F5,F6" and their selected value is "None" even though it was set to something else
am i missing some special ascx related event?
here's some of my code:
details.ascx
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="Details.ascx.vb" Inherits="Project.Details" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<div id="template_edit" style="background-color:red" runat="server">
<%-- div onto which all my controls are addded --%>
</div>
<div id="editfooter">
<asp:Button ID="Button_aceitar" Text="Update" runat="server" CommandName="Update" Visible="true"></asp:Button>
<asp:Button ID="Button2" Text="Insert" runat="server" CommandName="PerformInsert" Visible="true"></asp:Button>
<asp:Button ID="Button_cancelar" Text="Cancelar" runat="server" CausesValidation="False" CommandName="Cancel"></asp:Button>
<asp:Label ID="LabelLOG" runat="server" Text="Label" Visible="False"></asp:Label>
</div>
some of the code behind on details.ascx.vb
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack Then
Try
sOper = Session("OPERACAO_Edit")
gPeriodo = Session("PERIODO_Edit")
gClasse = Session("CLASSE_Edit")
gSistema = Session("SISTEMA_Edit")
Catch ex As Exception
End Try
gEG = Session("EntidGest")
Select Case gClasse & gSistema
Case 11
gMNID = 1
Case 12
gMNID = 2
Case 21
gMNID = 3
Case 22
gMNID = 4
Case 31
gMNID = 5
Case 32
gMNID = 6
End Select
Add_Controls(sOper)
Else
gPeriodo = Request.QueryString("periodo")
gClasse = Request.QueryString("classe")
gSistema = Request.QueryString("sistema")
gEG = Session("EntidGest")
Select Case gClasse & gSistema
Case 11
gMNID = 1
Case 12
gMNID = 2
Case 21
gMNID = 3
Case 22
gMNID = 4
Case 31
gMNID = 5
Case 32
gMNID = 6
End Select
End If
Catch ex As Exception
End Try
End Sub
Private Sub Detail_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Try
gVALIDATETEXT = "a-záâàãéêèíîìóôòõúûùçA-ZÁÂÀÃÉÊÈÍÎÌÓÔÒÕÚÛÙÇ .,;:/+\?!0-9<>_=&-"
gVALIDATETEXT = gVALIDATETEXT.Replace("a-z", "")
gVALIDATETEXT = gVALIDATETEXT.Replace("A-Z", "")
gVALIDATETEXT = gVALIDATETEXT.Replace("0-9", "")
Catch ex As Exception
gText = System.Reflection.MethodBase.GetCurrentMethod().Name & " Erro: " & Me.Page.ToString & " " & ex.Message
Add2LogFile(glogpath, gText)
End Try
End Sub
Private Sub Add_Controls(ByVal bOper As String)
'this bit of code is inside a loop that goes through some metadata, creates and adds controls to a div
Dim oCmb As New DropDownList
Dim oTextBox As New TextBox
Dim gSqlCMB As New SqlDataSource
Dim sValue as String
oCmb = New DropDownList
oCmb.ID = 'something dynamic
gSQL = "select c,t from table" 'the query is different for each dropdownlist
gSqlCMB.SelectCommand = gSQL
oCmb.DataSource = gSqlCMB
oCmb.DataValueField = "C"
oCmb.DataTextField = "T"
oCmb.SelectedValue = sValue '"1", "2", "3"....
oCmb.DataBind()
template_edit.controls.Add(oCmb)