Datagrid displaying

Results 1 to 2 of 2

Thread: Datagrid displaying

  1. #1
    Join Date
    Dec 1969

    Default Datagrid displaying

    Hello everyone..<BR><BR>I&#039;m trying to figure out how to use this datagrid object and I&#039;m afraid I have hit a snag. I can list all the data from a connection to the database, but now I want to modify that data slightly before it is rendered. The data returned is similar to the following:<BR><BR>JOHN DOE - 12345<BR>MARK SMITH - 27712<BR>BILLY JO BOB - 38472<BR>JULIE ROBERTS - 58234<BR><BR>For starters, I&#039;d like to format the names correctly. I&#039;d also like to, for instance, turn Mark Smith red and leave all other records the same color. With straight ASP, I looped the records and just sent everything to a function for formating and used an if statement for coloring.<BR><BR>I feel like I have big bulky gloves on with Asp.Net. :) Any suggestions/tutorials/etc?<BR><BR>Frij

  2. #2
    Join Date
    Dec 1969

    Default RE: Datagrid displaying

    The data grid will not let you alter the data (at least as far as I&#039;ve seen). The thing you have to do is get the data back and put it into a dataView. From there you can loop through the dataView and make as many changes as you want. I will ussually send the dataView into a function and do the mods there.<BR><BR>(IE) Note the Table name in the FILL command<BR><BR>Public Function FunctionName() As DataSet<BR><BR> &#039; Create Instance of Connection and Command Object<BR> Dim myConnection As New SqlConnection ConfigurationSettings.AppSettings("connectionStrin g"))<BR> Dim myCommand As New SqlDataAdapter("SqlCall", myConnection)<BR><BR> &#039; Mark the Command as a SPROC<BR> myCommand.SelectCommand.CommandType = CommandType.StoredProcedure<BR><BR> &#039; Add Parameters to SPROC<BR> Dim parameter As New SqlParameter("@VAr", SqlDbType.Int, 4)<BR> parameter.Value = Var<BR> myCommand.SelectCommand.Parameters.Add(parameter)< BR><BR> &#039; Create and Fill the DataSet<BR> Dim myDataSet As New DataSet()<BR> myCommand.Fill(myDataSet, "TableName")<BR><BR> &#039; Return the DataSet<BR> Return myDataSet<BR><BR>End Function<BR><BR><BR>---Then call the Function and make a VIEW<BR><BR> Dim MyView As DataView<BR> MyView = ShowEvent.GetEventsAll().Tables("TableName").Defau ltView<BR><BR><BR>---Then go through the dataView and do what you want.<BR><BR> Dim ColumnIndex = MyView.Table.Columns.IndexOf("ColumnName")<BR> Dim i As Integer<BR> For i = 0 To dvEventView.Table.Rows.Count - 1<BR> If Not IsDBNull(MyView.Item(i).Item(ColumnIndex)) Then<BR> WhatEver = MyView.Item(i).Item(ColumnIndex)<BR> i = i + 1<BR> End If<BR> Next<BR><BR>--Then Bind this &#039;MyView&#039; to the datagrid you want to display.<BR> Remember to Dispose of the View when you are done. This can make for a big hit on proformance if you are dealing with large databases.<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts