主题:  Datalist问题:为何要点2次才能进入“选中”状态?

dreamexpress_5d

职务:普通成员
等级:1
金币:10.0
发贴:2229
#12004/9/22 10:30:18
使用ASP.net做网页时,想用DATALIST做一个部门信息的表,点击其中的链接[X],就会展开该部门的详细信息。但要看每个部门的信息均要要点[X]2次才行(不是双击):第1次点网页无反应(IE状态栏显示提交进度条,但网页内容不更新),第2次再点同一部门时,就会展开该部门,如第2次点的是别的部门,会展开第1次的部门信息,而不是所选的(第2次点的[X])。

这是为何???请高人指点一下,谢谢.如何解决这个问题?一般用户总不习


图片如下:

图片如下:


HTML中的代码:
图片如下:


程序代码:
图片如下:

编辑历史:[此帖最近一次被 dreamexpress 编辑过(编辑时间:2004-09-22 10:43:04)]


dreamexpress_5d

职务:普通成员
等级:1
金币:10.0
发贴:2229
#22004/9/22 22:24:02
原来每次都权绑定才行!解决了~
图片如下:

图片如下:

图片如下:



dreamexpress_5d

职务:普通成员
等级:1
金币:10.0
发贴:2229
#32004/9/22 22:29:43
Imports SidriWeb.sidriNameSpace
Public Class testDatalist

    Inherits System.Web.UI.Page

#Region " Web 窗体设计器生成的代码 "

    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents DataList1 As System.Web.UI.WebControls.DataList
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button

    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
    '不要删除或移动它。
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub

#End Region
    Public nnn As Date

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码
        If Not Page.IsPostBack Then
            binddatalist()


        End If




    End Sub



    Private Sub DataList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataList1.SelectedIndexChanged
        DataList1.EditItemIndex = -1

        binddatalist()
    End Sub


    Private Sub binddatalist()
        ObjSql.strSQL = "select * from department"
        If DataList1.SelectedIndex >= 0 Or DataList1.EditItemIndex >= 0 Then
            ObjSql.strSQL = "select D.*,E.realname from department D left join employee E on D.dpthead=E.userid "
        End If

        Dim dr As SqlClient.SqlDataReader = ObjSql.SelectFromDBrd()
        DataList1.DataSource = dr

        DataList1.DataKeyField = "dptid"

        DataList1.DataBind()
        dr.Close()

        If DataList1.SelectedIndex >= 0 Then
            Dim dli As DataListItem = DataList1.Items(DataList1.SelectedIndex)
            Dim litdpthead As Literal = DirectCast(dli.FindControl("litdptheadp"), Literal)
            If Not IsNumeric(litdpthead.Text) Then
                Dim Label7 As Label = DirectCast(dli.FindControl("Label7"), Label)
                Label7.Text = "无部门领导"
            End If
        End If

        If DataList1.EditItemIndex >= 0 Then
            Dim dli As DataListItem = DataList1.Items(DataList1.EditItemIndex)
            Dim Ddldpthead1 As DropDownList = DirectCast(dli.FindControl("Ddldpthead"), DropDownList)
            FillListControl(Ddldpthead1, "employee", "Realname", "userid")
            Ddldpthead1.Items.Insert(0, New ListItem("无部门领导", "-100"))

            Dim litdpthead As Literal = DirectCast(dli.FindControl("litdpthead"), Literal)
            If IsNumeric(litdpthead.Text) Then
                SelectItemFromvalue(Ddldpthead1, litdpthead.Text)
            Else
                Ddldpthead1.SelectedIndex = 0
            End If
        End If
    End Sub

    Private Sub DataList1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.EditCommand
        DataList1.SelectedIndex = -1
        DataList1.EditItemIndex = e.Item.ItemIndex

        binddatalist()
    End Sub

    Private Sub DataList1_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.CancelCommand
        DataList1.EditItemIndex = -1
        DataList1.SelectedIndex = -1
        binddatalist()
    End Sub

   
End Class

编辑历史:[此帖最近一次被 dreamexpress 编辑过(编辑时间:2004-09-23 10:52:25)]


dreamexpress_5d

职务:普通成员
等级:1
金币:10.0
发贴:2229
#42004/9/23 10:52:46
FindControl方法好象很厉害啊!