我正在使用Visual Studio 2005和ASP。 NET 2.0与此程序。这是用VB.net编写的
现在,我们已经有一个Gridview嵌入并数据绑定到另一个gridview。第二个Gridview默认隐藏,并由用户扩展。在第二个gridview中有几个DropDownLists。问题是,每当我更改selecteditem时,这些DropDownLists都不会触发OnSelectedIndexChanged功能,也不会触发AutoPostback。
我很好奇它为什么不开火。谢谢。
Gridview1:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
Dim row As GridViewRow = e.Row
Dim strSort As String = String.Empty
Dim strCNRNum As String
' Make sure we aren't in header/footer rows
If row.DataItem Is Nothing Then
Return
End If
' Find Child GridView control
Dim gv As GridView = New GridView()
gv = row.FindControl("GridView2")
If gv.UniqueID = gvUniqueID Then
gv.EditIndex = gvEditIndex
ClientScript.RegisterStartupScript(GetType(Page), "Expand", "<SCRIPT LANGUAGE='javascript'>expandcollapse('div" + e.Row.DataItem("CNR_NUM").ToString() & "','one');</script>")
End If
' Prepare the query for Child GridView by passing
' the Customer ID of the parent row
'Dim dsTemp As SqlDataSource
'dsTemp = ChildDataSource(e.Row.DataItem("CNR_NUM").ToString, strSort)
'gv.DataSource = dsTemp
'gv.DataBind()
strCNRNum = e.Row.DataItem("CNR_NUM").ToString()
Dim dt As DataTable = New DataTable()
Dim con As SqlConnection = New SqlConnection(ConnectionString)
Try
con.Open()
Dim strSQL As String
strSQL = "select " & _
"CS.SID, " & _
"CS.CNR_NUM, " & _
"CS.STEP_NUM, " & _
"CS.SERVER_ID, " & _
"S.SERVER_NM, " & _
"CS.DATABASE_ID, " & _
"D.DATABASE_NM, " & _
"CS.CMD_FILE_NM, " & _
"CS.EXECUTE_DTTM, " & _
"CS.STEP_TYPE_ID, " & _
"ST.STEP_TYPE, " & _
"ISNULL(CS.LOG_FILE_NM,'') as LOG_FILE_NM " & _
"from " & _
"dbo.CNR_STEPS CS INNER JOIN dbo.CNR_SERVERS S on CS.SERVER_ID = S.SERVER_ID " & _
"INNER JOIN dbo.CNR_DATABASES D ON CS.DATABASE_ID = D.DATABASE_ID " & _
"INNER JOIN dbo.CNR_STEP_TYPES ST ON CS.STEP_TYPE_ID = ST.STEP_TYPE_ID " & _
"where " & _
"CS.CNR_NUM = '" & strCNRNum & "' " & _
"order by " & _
"CS.STEP_NUM"
Dim cmd As SqlCommand = New SqlCommand(strSQL, con)
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
da.Fill(dt)
If dt.Rows.Count > 0 Then
gv.DataSource = dt
gv.DataBind()
Else
dt.Rows.Add(dt.NewRow())
dt.Rows(0)("CNR_NUM") = strCNRNum
dt.Rows(0)("LOG_FILE_NM") = ""
gv.DataSource = dt
gv.DataBind()
Dim colCount As Integer = gv.Columns.Count
gv.Rows(0).Cells.Clear()
gv.Rows(0).Cells.Add(New TableCell())
gv.Rows(0).Cells(0).ColumnSpan = colCount
gv.Rows(0).Cells(0).HorizontalAlign = HorizontalAlign.Center
gv.Rows(0).Cells(0).ForeColor = System.Drawing.Color.Red
gv.Rows(0).Cells(0).Font.Bold = True
gv.Rows(0).Cells(0).Text = "No Steps Defined"
End If
Catch ex As Exception
lblMessage.ForeColor = Drawing.Color.Red
lblMessage.Text = "Error: " & ex.Message.ToString()
'ClientScript.RegisterStartupScript(GetType(Page), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + ex.Message.ToString().Replace("'", "") + "');</script>")
End Try
End Sub
第二个gridview的ASP代码,它位于第一个:
<asp:GridView ID="GridView2" AllowPaging="True" AllowSorting="true" Width="100%" Font-Size="Small" AutoGenerateColumns="false" runat="server" DataKeyNames="CNR_NUM" ShowFooter="true" OnRowEditing = "GridView2_RowEditing"
OnRowCommand = "GridView2_RowCommand"
OnRowDeleting = "GridView2_RowDeleting"
OnRowDeleted = "GridView2_RowDeleted"
OnRowUpdating = "GridView2_RowUpdating"
OnRowUpdated = "GridView2_RowUpdated"
OnRowCancelingEdit = "GridView2_CancelingEdit"
OnRowDatabound="GridView2_RowDataBound"
CssClass="mGrid"
PagerStyle-CssClass="pgr"
>
<HeaderStyle Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="Step Type">
<ItemTemplate><%#Eval("STEP_TYPE")%></ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddl_StepTypes"
DataSourceID="ds_StepTypes"
SelectedValue='<%# Eval("STEP_TYPE_ID")%>'
DataTextField="STEP_TYPE"
DataValueField="STEP_TYPE_ID"
runat="server"
Width="100px"
Font-Size="X-Small"
AutoPostBack="true"
OnSelectedIndexChanged = "ddl_StepTypes_SelectedIndexChanged">
</asp:DropDownList>
<label id="lblTest"></label>
<!--<asp:TextBox ID="txtStepType" Text='<%# Eval("SERVER_ID")%>' runat="server"></asp:TextBox>-->
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList DataSourceID="ds_StepTypes"
DataTextField="STEP_TYPE" DataValueField="STEP_TYPE_ID" ID="ddl_StepTypes" runat="server" Width="100px" Font-Size="X-Small"></asp:DropDownList>
<!--<asp:TextBox ID="txtStepType" Text='' runat="server"></asp:TextBox>-->
</FooterTemplate>
</asp:TemplateField>
如果需要更多信息,请告知我们。谢谢。