Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No data displayed making a Data Grid on ASP.net

Status
Not open for further replies.

cgalesi

IS-IT--Management
Nov 5, 2002
4
BR
Hello Everyone!!

I'm trying to make a data grid but, after create a data set correctly (I guess), nothing is displayed running the solution.

Someone knows what could happens??

Thank's

Galesi - Brazil
 
Many different reasons this may be happening. Code will always help us help you.

The most probable reason is that you haven't called .dataBind() on the datagrid once you set the .dataSource

Remember that 'databind' is to aspnet developers what 'abracadabra' is to David Copperfield.

paul
penny1.gif
penny1.gif
 
First of all, thank's for your cooperation.

Ok Paul!! You asked:

Protected cs As String= "Provider=Microsoft.Jet.OLEDB.4.0;Password="";User ID=Admin;Data Source=C:\Inetpub\ Deny None;Extended Properties="";Jet OLEDB:System database="";Jet OLEDB:Registry Path="";Jet OLEDB:Database Password="";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False"

Protected ss As String = "SELECT * from T_ORG_EXT"
Dim bEditing As Boolean = False
Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)

If Not Page.IsPostBack Then
Label1.Text = "ASC"
BindGrid()
End If
End Sub

Sub BindGrid()

'Dim sMapPath As String
'sMapPath = Server.MapPath("db\teste.mdb")
'cs = cs & sMapPath
Dim dc As New OleDb.OleDbConnection(cs)
Dim da As New OleDb.OleDbDataAdapter(ss, dc)
Dim ds As New DataSet()

da.Fill(ds)
da.Fill(ds, "T_ORG_EXT")
Dim dv As DataView = ds.Tables("T_ORG_EXT").DefaultView
If Label2.Text <> &quot;&quot; Then dv.Sort = Label2.Text + &quot; &quot; + Label1.Text
dg.DataSource = dv
dg.DataBind()
End Sub

Sub dg_Page(ByVal Sender As Object, ByVal E As DataGridPageChangedEventArgs)
If Not bEditing Then
dg.CurrentPageIndex = E.NewPageIndex
BindGrid()
End If
End Sub

Sub dg_Sort(ByVal Sender As Object, ByVal E As DataGridSortCommandEventArgs)
If Not bEditing Then
If Label2.Text = E.SortExpression Then
If Label1.Text = &quot;ASC&quot; Then
Label1.Text = &quot;DESC&quot;
Else
Label1.Text = &quot;ASC&quot;
End If
End If
Label2.Text = E.SortExpression
BindGrid()
End If
End Sub

Sub dg_Edit(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
If Not bEditing Then
dg.EditItemIndex = e.Item.ItemIndex
BindGrid()
SingleColumn(False)
End If
End Sub

Sub dg_Cancel(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
dg.EditItemIndex = -1
BindGrid()
SingleColumn(True)
End Sub

Sub dg_Update(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
dg.EditItemIndex = -1
Dim strcmd As String = &quot;UPDATE T_ORG_EXT SET &quot;
Dim pkvalue As String = dg.DataKeys(CInt(e.Item.ItemIndex))
strcmd = strcmd & &quot; WHERE ROW_ID = &quot; & pkvalue
Dim dc As New OleDb.OleDbConnection(cs)
Dim cmd As New OleDb.OleDbCommand(strcmd, dc)
Try
dc.Open()
cmd.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
Label3.Text = ex.ToString()
Finally
dc.Close()
End Try
BindGrid()
SingleColumn(True)
End Sub

Sub dg_Delete(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)
If Not bEditing Then
Dim pkvalue As String = dg.DataKeys(CInt(E.Item.ItemIndex))
Dim dc As New OleDb.OleDbConnection(cs)
Dim cmd As New OleDb.OleDbCommand(&quot;DELETE from T_ORG_EXT where ROW_ID = &quot; & pkvalue, dc)
dc.Open()
cmd.ExecuteNonQuery()
dc.Close()
dg.CurrentPageIndex = 0
dg.EditItemIndex = -1
BindGrid()
End If
End Sub

Sub dg_ItemCreated(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim deletebutton As WebControl = CType(e.Item.Cells(dg.Columns.Count - 1).Controls(0), WebControl)
deletebutton.Attributes.Add(&quot;onclick&quot;, _
&quot;return confirm('Are you sure you want to delete this record?');&quot;)
End If
End Sub

Sub dg_Add(ByVal Sender As Object, ByVal E As EventArgs)
CheckEditing(&quot;&quot;)
If Not bEditing Then
Dim dc As New OleDb.OleDbConnection(cs)
Dim cmd As New OleDb.OleDbCommand(&quot;INSERT into T_ORG_EXT(NAME,AMT) Values ('','')&quot;, dc)
dc.Open()
cmd.ExecuteNonQuery()
dc.Close()
dg.CurrentPageIndex = dg.PageCount - 1
BindGrid()
SingleColumn(False)
dg.EditItemIndex = dg.Items.Count - 1
BindGrid()
End If
End Sub

Sub SingleColumn(ByVal b As Boolean)
Dim i As Integer
For i = 2 To dg.Columns.Count - 1
dg.Columns(i).Visible = b
Next
Label3.Text = &quot;&quot;
End Sub

Sub dg_Item(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)
CheckEditing(E.CommandName)
End Sub

Sub CheckEditing(ByVal commandName As String)
If dg.EditItemIndex <> -1 Then
If commandName <> &quot;Cancel&quot; And commandName <> &quot;Update&quot; Then
Label3.Text = &quot;Please click update to save your changes, or cancel to discard your changes, before selecting another item.&quot;
bEditing = True
End If
End If
End Sub


I don't know if it is necessary to create the oledbconnection and the oledbadapter on the design view or if only on the code is enough.

Thank you again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top