我一直在试用telerik的ajax控件,到目前为止他们还没有给我带来很大的问题。我正在使用带有编辑功能的ajax radgrid,他们的一个建议是使用以控件编程方式填充的Web表单用户控件(.ascx)来编辑特定的网格记录。
我可以正常打开网络表单,并使用以下控件填写代码隐藏:
对于网格,我一直在测试编辑功能,要编辑记录,我需要3个下拉列表才能正确编辑它,现在这就是我的问题所在。
我有一个函数可以添加记录,如果它们符合某些元数据标准,如果我在添加控件之间放置一个断点并执行以下步骤:
添加第二行""控件(标签和下拉列表)
如果我停在此处并结束该功能,则会发生以下情况,两个标签都有正确的文本和文本框,但下拉列表没那么多,即使我已经设置了所选索引的值和#34; 2"并且在quickwatch中它保持为2,一旦显示Web表单,默认值值将重置为" 0"
添加第三行"行"控件(标签和下拉列表)
如果我在这里停下来并进入功能的结尾,即使在quickwatch中一切都很好,一旦显示/加载了Web表单,两个下拉列表中都会有相同的值,他们都会有他们的selectedindex = 0
编辑:我将描述我期待的行为:
这是我得到的行为:
加载网络表单后,下拉列表(1)和下拉列表(2)将填充"无,F1,F2,F3,F4,F5,F6和#34;并且他们选择的值是"无"即使它被设置为其他东西
我错过了一些特殊的ascx相关事件吗?
这是我的一些代码:
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>
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)