Datagrid displaying

fireblazer

New Member
Hello everyone..<BR><BR>I'm trying to figure out how to use this datagrid object and I'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'd like to format the names correctly. I'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>FrijThe data grid will not let you alter the data (at least as far as I'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> ' Create Instance of Connection and Command Object<BR> Dim myConnection As New SqlConnection ConfigurationSettings.AppSettings("connectionString"))<BR> Dim myCommand As New SqlDataAdapter("SqlCall", myConnection)<BR><BR> ' Mark the Command as a SPROC<BR> myCommand.SelectCommand.CommandType = CommandType.StoredProcedure<BR><BR> ' Add Parameters to SPROC<BR> Dim parameter As New SqlParameter("@VAr", SqlDbType.Int, 4)<BR> parameter.Value = http://aspmessageboard.com/archive/index.php/Var<BR> myCommand.SelectCommand.Parameters.Add(parameter)<BR><BR> ' Create and Fill the DataSet<BR> Dim myDataSet As New DataSet()<BR> myCommand.Fill(myDataSet, "TableName")<BR><BR> ' 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").DefaultView<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 'MyView' 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>
 
Back
Top