请教各位,为什么我点击第二页时或点击下载按钮时,datagrid就消失了?请问哪里出错了?谢谢!!!而且要保证取值的正确性。
代码如下:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
datagrid1.DataSource = CreateDataSource()
'datagrid1.DataSource = dv
datagrid1.DataBind()
End If
End Sub
Function CreateDataSource() As ICollection
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dt.Rows.Add(dr)
Next i
Dim dv As New DataView(dt)
Return dv
End Function 'CreateDataSource
Sub detailsClicked(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Try
Dim buttonColumn As TableCell = e.Item.Cells(1)
Dim buttonColText As String = buttonColumn.Text
TextBox1.Text = buttonColText
Catch ex As Exception
End Try
End Sub
Private Sub datagrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles datagrid1.PageIndexChanged
datagrid1.CurrentPageIndex = e.NewPageIndex
datagrid1.DataBind()
End Sub
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<ASP:DATAGRID id="datagrid1" runat="server" Font-Size="8pt" Width="80%" BorderColor="Tan" BorderWidth="1px"
BackColor="LightGoldenrodYellow" CellPadding="2" GridLines="None" OnItemCommand="detailsClicked"
showfooter="True" AllowSorting="True" PagerStyle-PageButtonCount="10" HorizontalAlign="Center"
EnableViewState="False" HeaderStyle-BackColor="#aaaadd" Font-Name="Verdana" Font-Names="Verdana"
ForeColor="Black" AllowPaging="True" PageSize="5" PagerStyle-Mode="NumericPages">
<SelectedItemStyle ForeColor="GhostWhite" BackColor="DarkSlateBlue"></SelectedItemStyle>
<AlternatingItemStyle BackColor="PaleGoldenrod"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" BackColor="Tan"></HeaderStyle>
<FooterStyle BackColor="Tan"></FooterStyle>
<Columns>
<asp:ButtonColumn Text="下载" ButtonType="PushButton" CommandName="details"></asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>
</ASP:DATAGRID>
<asp:TextBox id="TextBox1" runat="server" Width="168px"></asp:TextBox>
</form>
</body>