datagrid sorting help?

bicsi_webmaster

New member
Joined
Jul 11, 2006
Messages
1
Programming Experience
Beginner
Greetings! I need some assistance using the datagrid with my code to view the data in order!

HTML:
<%@ Page Language="VB"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
VB.NET:
Public Sub Page_Load(Source As Object, E As EventArgs)
Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("DSN2"))
Dim myCommand As SqlCommand = New SqlCommand("GetPublications", myConnection)
myCommand.CommandType = CommandType.StoredProcedure
Try
myConnection.Open()
Dim result As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
MyDataGrid.DataSource=result
MyDataGrid.DataBind()
result.Close()
If MyDataGrid.Items.Count = 0 Then
MyDataGrid.Visible =False
Else
MyDataGrid.Visible =True
End If
Catch SQLexc As SqlException
lblStatus.Text = "Error while processing database request - <b>ERROR:<br><font color=""red"">" & SQLexc.ToString() & "</font></b>"
End Try
End Sub
 
 
Public Sub UpdateItem(ByVal ItemID As Integer, ByVal quantity As Integer)
If quantity > 0 Then
Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("DSN2"))
Dim myCommand As SqlCommand = New SqlCommand("AddPublicationOrder", myConnection)
myCommand.CommandType = CommandType.StoredProcedure
Dim InvoiceID As SqlParameter = New SqlParameter("@InvoiceID", SqlDbType.Int)
InvoiceID.Value = Request.Cookies("BICSI-Invoice").Value
myCommand.Parameters.Add(InvoiceID)
Dim PublicationID As SqlParameter = New SqlParameter("@PublicationID", SqlDbType.Int)
PublicationID.Value = ItemID
myCommand.Parameters.Add(PublicationID)
Dim parameterQuantity As SqlParameter = New SqlParameter("@Quantity", SqlDbType.Int)
parameterQuantity.Value = quantity
myCommand.Parameters.Add(parameterQuantity)
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
End If
 
End Sub
 
 
Sub Checkout_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
Dim myCommand as SqlCommand = new SqlCommand()
myCommand.Connection = new SqlConnection(ConfigurationSettings.AppSettings("DSN2"))
myCommand.Connection.Open()
myCommand.CommandText = "DeletePublicationOrder"
myCommand.CommandType = CommandType.StoredProcedure
Dim myID as SQLParameter = new SQLParameter("@InvoiceID", SqlDbType.Int)
myID.Value = Request.Cookies("BICSI-Invoice").Value
myCommand.Parameters.Add(myID)
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()
 
Dim i As Integer
For i = 0 To MyDataGrid.Items.Count - 1
Dim quantityTxt As TextBox = CType(MyDataGrid.Items(i).FindControl("Quantity"), TextBox)
Dim quantity as Integer
If quantityTxt.Text = "" Then
quantity = 0
Else
quantity = CInt(quantityTxt.Text)
End If
 
Dim lblItemID As Label = Ctype(MyDataGrid.Items(i).FindControl("ItemID"), Label)
UpdateItem(CInt(lblItemID.Text), quantity)
Next
Response.Redirect("ShippingInfo.aspx?InvoiceID=" & Request.Cookies("BICSI-Invoice").Value)
End Sub
Here is the data grid component
HTML:
<asp:DataGrid runat="server" id="myDataGrid"
AutoGenerateColumns="False"
EnableViewState="True"
align="left"
Border="1"
Cellpadding="1"
Cellspacing="0"
Width="80%"
AlternatingItemStyle-BackColor="#CCCCCC"
HeaderStyle-Font-Size="small"
HeaderStyle-Font-Bold="True"
HeaderStyle-Backcolor="#000066"
HeaderStyle-Forecolor="white"
ItemStyle-Font-Size="x-small"
ItemStyle-BackColor="#FFFFFF"
ShowHeader="true"
CssClass="DataGrid"
AllowPaging="False"
AllowSorting="True"
>
Any help in changing or adding to my code would be helpful thanks!
 
Last edited by a moderator:
Try adding bound columns to the datagrid ether using the rClick -> property builder ... or adding:
VB.NET:
<asp:BoundColumn DataField="ColumnName" HeaderText="Column Name"> </asp:BoundColumn>
for each column you wish to show.

If you already have this you may wish to check the stored proc.
g
 
Back
Top