我在webform visual studio项目中有两个gridviews。第一个是固定大小的网格,使用javascript,我设法设置返回网格引用,然后输出到两个文本框。然后,这些文本框更新第二个网格,其中的记录与第一个网格的单击单元格中的数字相关:
第一个gridview是彩色的,第二个gridview是它下面的短划线文本。在该示例中,您可以看到所选择的单元格引用是D和3a,下面的第二个网格显示了6个学生的名字,单元格D 3a中的数字是指的。这非常有效。但是,在我多次点击网格后,布局变得混乱:
正如您所看到的那样,渲染的标题会消失,这会导致布局问题以及随后的网格参考定位问题。
在第一个gridview的数据绑定事件中,我有以下vbcode,它会在gridview上生成额外的标题,消失:
If gvProgressGrid IsNot Nothing Then
Dim row As New GridViewRow(0, -1, DataControlRowType.Header, DataControlRowState.Normal)
Dim left As TableCell = New TableHeaderCell()
left.ColumnSpan = 2
row.Cells.Add(left)
left.BorderStyle = BorderStyle.None
Dim grades As TableCell = New TableHeaderCell()
grades.ColumnSpan = 10
grades.Text = "Grades"
row.Cells.Add(grades)
Dim cohort As TableCell = New TableHeaderCell()
cohort.ColumnSpan = 1
cohort.Text = "Cohort"
cohort.RowSpan = 2
cohort.BackColor = Drawing.Color.FromArgb(242, 242, 242)
row.Cells.Add(cohort)
Dim expected As TableCell = New TableHeaderCell()
expected.ColumnSpan = 2
Select Case strYear
Case "11"
expected.Text = "Students achieving expected progress (3 or more levels)"
Case "10"
expected.Text = "Students achieving expected progress (2 or more levels)"
Case "9"
expected.Text = "Students achieving expected progress (1 or more levels)"
End Select
expected.BackColor = Drawing.Color.FromArgb(216, 216, 216)
expected.Width = 250
row.Cells.Add(expected)
Dim above As TableCell = New TableHeaderCell()
above.ColumnSpan = 2
Select Case strYear
Case "11"
above.Text = "Students achieving above expected progress (4 or more levels)"
Case "10"
above.Text = "Students achieving above expected progress (3 or more levels)"
Case "9"
above.Text = "Students achieving above expected progress (2 or more levels)"
End Select
above.BackColor = Drawing.Color.FromArgb(242, 242, 242)
above.Width = 250
row.Cells.Add(above)
Dim t As Table = TryCast(gvProgressGrid.Controls(0), Table)
If t IsNot Nothing Then
t.Rows.AddAt(0, row)
End If
End If
我使用javascript中的以下代码(在点击时抓取第一个gridview的网格参考的脚本)自动触发第二个文本框上的文本更改/焦点丢失:
document.getElementById("<%=tbKS2.ClientID%>").value = strKS2;
__doPostBack(document.getElementById("<%=tbKS2.ClientID%>").name, '')
只有第二个网格视图需要在单击第一个网格时更新,并且看起来好像整个页面或者至少第一个网格视图也在更新。
如何才能获得它,以便在触发上述文本框回发后,只更新我的第二个gridview并且页面上的其余元素保持呈现方式?
感谢。
答案 0 :(得分:1)
您需要在网格的 RowCreated 事件期间插入行:
Private Sub gvProgressGrid_RowCreated(sender As Object, e As GridViewRowEventArgs) Handles gvProgressGrid.RowCreated
If e.Row.RowType = DataControlRowType.Header Then
' the rest of your code
' ...
' ...
End If
End Sub