2011-01-19 39 views
0

此事件不會被解僱 - 不知道爲什麼ASP.net Dropdowlist在運行時添加 - 事件處理程序不被解僱

Protected Sub ddl_selectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) 
    Dim a As String = "" 
    'this does not get fired 
End Sub 


<asp:GridView ID="GridViewAssignment" runat="server" BackColor="White" BorderColor="White" 
            BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" GridLines="None" 
            Width="100%"> 
            <RowStyle BackColor="#DEDFDE" ForeColor="Black" /> 
            <FooterStyle BackColor="#C6C3C6" ForeColor="Black" /> 
            <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" /> 
            <SelectedRowStyle BackColor="#86A4CA" Font-Bold="True" ForeColor="White" /> 
            <HeaderStyle BackColor="#808080" Font-Bold="True" ForeColor="#E7E7FF" /> 
    </asp:GridView> 

保護小組GridViewAssignment_RowDataBound(BYVAL發件人爲對象,BYVALË作爲的System.Web.UI .WebControls.GridViewRowEventArgs)處理GridViewAssignment.RowDataBound

Dim dateApplicationCreatedCell As TableCell = e.Row.Cells(0) 'app created on 
    Dim typeOfReview As TableCell = e.Row.Cells(7) 'type 
    Dim QCCell As TableCell = e.Row.Cells(8) 'qc 
    Dim dateReviewAssignedCell As TableCell = e.Row.Cells(9) 'date assigned 
    Dim reviewerNameCell As TableCell = e.Row.Cells(10) 'reviewer 
    Dim dateReviewCompletedCell As TableCell = e.Row.Cells(11) 'date completed review 

    Dim ddl As DropDownList 

    If e.Row.RowIndex <> -1 Then 
     If dateReviewAssignedCell.Text.Trim = "&nbsp;" Then 
      dateReviewAssignedCell.Text = Now.Date 
     End If 


     Dim sqlCondition As String = String.Empty 
     If dateReviewCompletedCell.Text.Trim = "&nbsp;" Then 
      Dim nameToSelect As String 

      If reviewerNameCell.Text.Trim <> "&nbsp;" Then 
       Dim dateReviewAssigned As Date = dateReviewAssignedCell.Text 
       Dim elapsedSinceAssigned As Long = DateDiff(DateInterval.Day, dateReviewAssigned.Date, Now.Date, Microsoft.VisualBasic.FirstDayOfWeek.Monday, FirstWeekOfYear.Jan1) 
       If elapsedSinceAssigned <= 3 Then 
        dateReviewAssignedCell.BackColor = Drawing.Color.LightGreen 
       ElseIf elapsedSinceAssigned > 3 And elapsedSinceAssigned <= 5 Then 
        dateReviewAssignedCell.BackColor = Drawing.Color.Yellow 
       ElseIf elapsedSinceAssigned > 5 Then 
        dateReviewAssignedCell.BackColor = Drawing.Color.OrangeRed 
       End If 
       nameToSelect = reviewerNameCell.Text.Trim 
      Else 
       nameToSelect = String.Empty 

      End If 


      If QCCell.Text.ToLower.Contains("qc") Then 
       If typeOfReview.Text.ToLower.Contains("bca") Then 
        sqlCondition = "where [QCRole_Level1] = 1 and [BCA] = 1" 
       ElseIf typeOfReview.Text.ToLower.Contains("ehp") Then 
        sqlCondition = "where [QCRole_Level1] = 1 and [EHP] = 1" 
       ElseIf typeOfReview.Text.ToLower.Contains("eligibility") Then 
        sqlCondition = "where [QCRole_Level1] = 1 and [ProgramEligibility] = 1" 
       ElseIf typeOfReview.Text.ToLower.Contains("engineering") Then 
        sqlCondition = "where [QCRole_Level1] = 1 and [Engineering] = 1" 
       End If 
      ElseIf QCCell.Text.ToLower.Contains("initial") Then 
       If typeOfReview.Text.ToLower.Contains("bca") Then 
        sqlCondition = "where [BCA] = 1" 
       ElseIf typeOfReview.Text.ToLower.Contains("ehp") Then 
        sqlCondition = "where [EHP] = 1" 
       ElseIf typeOfReview.Text.ToLower.Contains("eligibility") Then 
        sqlCondition = "where [ProgramEligibility] = 1" 
       ElseIf typeOfReview.Text.ToLower.Contains("engineering") Then 
        sqlCondition = "where [Engineering] = 1" 
       End If 
      ElseIf QCCell.Text.ToLower.Contains("letter") Then 
       sqlCondition = "where [FinalLetter] = 1" 
      End If 


      ddl = New DropDownList 
      ddl.EnableViewState = True 
      ddl.AutoPostBack = True 

      AddHandler ddl.SelectedIndexChanged, AddressOf ddl_selectedIndexChanged 

      ddl.Width = New Unit(110, UnitType.Pixel) 
      dropDownListSelect(ddl, nameToSelect, sqlCondition) 
      reviewerNameCell.Controls.Add(ddl) 



     End If 
    End If 
End Sub 

Protected Sub GridViewAssignment_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridViewAssignment.SelectedIndexChanged 

End Sub 


Protected Sub dropDownListSelect(ByVal ddlist As DropDownList, ByVal valueToSelect As String, ByVal sqlFilterString As String) 

    Dim sqlQuery As String = "SELECT [ReviewerName],[Specialty],[Tiger],[Triage]" + _ 
    ",[ProgramEligibility],[Engineering],[BCA],[EHP],[QCRole_Level1],[QCRole_Overall]" + _ 
    ",[FinalLetter] FROM [SubApplicationTracker].[dbo].[ReviewerResources] " + _ 
    sqlFilterString + " order by ReviewerName asc" 


    Dim connStr As String = System.Configuration.ConfigurationManager.ConnectionStrings("SubAppTrackerConnString").ConnectionString 
    Dim sqlconnection As SqlConnection = New SqlConnection(connStr) 
    sqlconnection.Open() 
    Dim sqlCommand As SqlCommand = New SqlCommand(sqlQuery, sqlconnection) 
    Dim dr As SqlDataReader = sqlCommand.ExecuteReader 
    ddlist.Items.Clear() 
    ddlist.Items.Add("") 
    Do While dr.Read 

     Dim itemToAdd As New ListItem 
     itemToAdd.Text = dr("ReviewerName") 
     itemToAdd.Value = dr("ReviewerName") 
     ddlist.Items.Add(itemToAdd) 
    Loop 

    'if we find no reviewer then combo should be at the blank item 
    If valueToSelect = String.Empty Then 
     ddlist.Items(0).Selected = True 
    Else 'if we find a matching value then combo should selected at that value 
     If ddlist.Items.FindByValue(valueToSelect) IsNot Nothing Then 
      ddlist.Items.FindByValue(valueToSelect).Selected = True 
     Else 'if we find a non empty value but it doesnt exist in the combo list then - add that item to combo list and select it 
      Dim newItem As New ListItem 
      newItem.Text = valueToSelect 
      newItem.Value = valueToSelect 
      ddlist.Items.Add(newItem) 
      ddlist.Items.FindByValue(valueToSelect).Selected = True 
     End If 
    End If 


End Sub 

回答

0

你需要的數據在每一個回傳結合在GridView,以獲取事件火?

+0

我打電話在頁面init中的gridview綁定,我做它無論回發 - 旁邊注意我有pregrader中發生gridview綁定,但我發現在下拉列表中選定的值沒有得到保留,並被建議在論壇切換到頁面初始化。 – ved 2011-01-19 20:01:27