0
我遇到以下問題,我想知道任何人都可以幫我找到解決方案。 我正在從sql server數據庫中檢索數據並在asp.net頁面的gridview中顯示信息。然而,其中一列會返回大量文本,這在asp.net頁面上顯得不太好,我想只修剪來自該列的文本。如何在GridDiew列中修剪數據,從數據庫中檢索
最初GridView的AutoGenerateColumn屬性被設置爲True,但是因爲我想修剪這個文本,所以我查看了手動綁定gridview的datacolumns,所以將此屬性更改爲False。我對vb.net相當陌生,所以我不確定從這裏走到哪裏,使用Template和ItemTemplates。
我重視我下面的代碼:
Asp.Net代碼:
<asp:GridView ID="grdStoredProcs" CssClass="grdView" runat="server" ForeColor="#333333" GridLines="None" Height="191px" Width="324px" Font-Italic="False" Font-Names="Arial" AutoGenerateColumns="false" >
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
</ItemTemplate>
</asp:Templatefield>
</Columns>
<AlternatingRowStyle BackColor="#C6C2C4" BorderColor="Black" BorderStyle="Groove" />
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle CssClass="gridViewHeader" BackColor="#990000" Font-Bold="True" ForeColor="White" Font-Size="Medium" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#A6A1A3" ForeColor="White" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
VB代碼:
Private Sub ddlStoredProcedureList_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlStoredProcedureList.SelectedIndexChanged
procLabel.Text = String.Empty
procLabel.Visible = True
Dim ds As DataSet
Dim errors As String = String.Empty
If Session("proctable") IsNot Nothing Then
ds = Session("proctable")
Else
ds = GetProcsList()
End If
Dim resultTable As New DataTable
If Not ds.Tables(0) Is Nothing Then
resultTable = ds.Tables(0)
End If
For Each row As DataRow In resultTable.Rows
If row.Item("proc").ToString = ddlStoredProcedureList.SelectedValue Then
procLabel.Text = row.Item("parametername").ToString
procLabel.Visible = True
procTextbox.Visible = True
ExecuteButton.Visible = True
ElseIf ddlStoredProcedureList.SelectedValue = "" Then
procLabel.Visible = False
procTextbox.Visible = False
ExecuteButton.Visible = False
grdStoredProcs.Visible = False
Exit For
End If
Next
End Sub
Protected Sub ExecuteButton_Click(sender As Object, e As EventArgs) Handles ExecuteButton.Click
Dim ds As DataSet
Dim colour As String = String.Empty
Dim systemError As String = String.Empty
'retrieve the session else retrieve from db
If Not Session("proctable") Is Nothing Then
ds = Session("proctable")
Else
ds = GetProcsList()
End If
Dim resultTable As New DataTable
If Not ds.Tables(0) Is Nothing Then
resultTable = ds.Tables(0)
End If
Dim name As String = String.Empty
'now loop through table to get proc name where it equals what the user selected
For Each row As DataRow In resultTable.Rows
If row.Item("proc").ToString = ddlStoredProcedureList.SelectedValue Then
name = row.Item("parametername").ToString
Exit For
End If
Next
If name.Length > 0 Then
'got a match
grdStoredProcs.DataSource = ExecuteProc(name)
grdStoredProcs.DataBind()
End If
End Sub
'check for errors in the log trace and highlight red
Protected Sub GridStoredProcs_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles grdStoredProcs.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.Cells(6).Text.Contains("Errors:") Then
e.Row.BackColor = System.Drawing.Color.Red
End If
End If
由於這是一個偉大的幫幫我。我只是在鑄造時遇到了一些問題,但希望我能夠解決這個問題。感謝幫助:) – user3481605