473,837 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGrid not showing data

nmm32
9 New Member
I have a DataGrid which displays data with the aid of a procedure.

I have tested the procedure inside the database and it is working fine.
I have another procedure which adds another row to the table, which is working fine inside the programming, and in the database.

However, I still cannot figure out what am I doing wrong with the DataGrid configurations OR Database OR DataAdapter OR SqlSelectComman d ... I really don't know yet and I have spent a lot of time in this tiny issue.

Below is additional information. Any help is extremely appreciated.

**On page Load a different page calls the method RefreshDataCrit eria, which it supposes to refresh the data in the DataGrid***

I have other pages that do the same thing:
when the user clicks on a certain link, in the main page, the link makes visible the control ( .ascx ) and then calls the function to refresh the data of the DataGrid. The other pages are working fine, except for this one.

----------------------------------------------------------
Code inside the HTML part:
[HTML]
<asp:datagrid id=dataGridCrit eria Width="466px" runat="server" Font-Size="XX-Small" DataKeyField="C ourseCriteriaID " DataMember="pro cWebSelectCours eCriteriaForSyl labus" DataSource="<%# DtsCourseCriter ias31 %>" BorderColor="#3 366CC" BorderWidth="1p x" BackColor="Whit e" CellPadding="4" BorderStyle="No ne" AutoGenerateCol umns="False" PageSize="5" Font-Names="sans-serif" AllowPaging="Tr ue" Height="120px">
<SelectedItemSt yle Font-Bold="True" ForeColor="#CCF F99" BackColor="#009 999"></SelectedItemSty le>
<ItemStyle Font-Size="XX-Small" Font-Names="Arial" Font-Bold="True" ForeColor="#003 399" BackColor="Whit e"></ItemStyle>
<HeaderStyle Font-Size="XX-Small" Font-Names="Arial" Font-Bold="True" ForeColor="#CCC CFF" BackColor="#003 399"></HeaderStyle>
<FooterStyle ForeColor="#003 399" BackColor="#99C CCC"></FooterStyle>
<Columns>
<asp:BoundColum n DataField="Prof OrgCriteriaID" HeaderText="Pro fOrgCriteriaID" ></asp:BoundColumn >
<asp:BoundColum n DataField="Prof OrgCriteriaCode " HeaderText="Pro fOrgCriteriaCod e"></asp:BoundColumn >
<asp:BoundColum n DataField="Prof OrgCriteriaDesc r" HeaderText="Pro fOrgCriteriaDes cr"></asp:BoundColumn >
<asp:BoundColum n DataField="Cour seCriteriaID" HeaderText="Cou rseCriteriaID"> </asp:BoundColumn >
<asp:ButtonColu mn Text="Delete" CommandName="De lete">
<HeaderStyle Width="50px"></HeaderStyle>
</asp:ButtonColum n>
</Columns>
<PagerStyle NextPageText="N ext Page" PrevPageText="P revious Page" HorizontalAlign ="Center" ForeColor="#003 399"
BackColor="#99C CCC"></PagerStyle>
</asp:datagrid>[/HTML]
-----------------------------------------------------------------------

Procedure:

Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE dbo.procWebSelectCourseCriteriaForSyllabus
  2.  
  3. @CourseCode varchar(20)
  4.  
  5. AS
  6.  
  7. SELECT     ProfOrgCriteria.ProfOrgCriteriaID, ProfOrgCriteria.ProfOrgCriteriaCode,ProfOrgCriteria.ProfOrgCriteriaDescr,CourseCriteria.CourseCriteriaID
  8. FROM         CourseCriteria INNER JOIN
  9.                       ProfOrgCriteria ON CourseCriteria.ProfOrgCriteriaID = ProfOrgCriteria.ProfOrgCriteriaID
  10. WHERE     (CourseCriteria.CourseCode = @CourseCode)
  11. GO
---------------------------------------------------------

DataSet:

[HTML]<?xml version="1.0" standalone="yes "?>
<xs:schema id="dtsCourseCr iterias3" targetNamespace ="http://www.tempuri.org/dtsCourseCriter ias3.xsd" xmlns:mstns="ht tp://www.tempuri.org/dtsCourseCriter ias3.xsd" xmlns="http://www.tempuri.org/dtsCourseCriter ias3.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata" attributeFormDe fault="qualifie d" elementFormDefa ult="qualified" >
<xs:element name="dtsCourse Criterias3" msdata:IsDataSe t="true">
<xs:complexType >
<xs:choice maxOccurs="unbo unded">
<xs:element name="procWebSe lectCourseCrite riaForSyllabus" >
<xs:complexType >
<xs:sequence>
<xs:element name="ProfOrgCr iteriaID" msdata:ReadOnly ="true" msdata:AutoIncr ement="true" type="xs:int" />
<xs:element name="ProfOrgCr iteriaCode" type="xs:string " />
<xs:element name="ProfOrgCr iteriaDescr" type="xs:string " />
<xs:element name="CourseCri teriaID" msdata:ReadOnly ="true" msdata:AutoIncr ement="true" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Table">
<xs:complexType >
<xs:sequence>
<xs:element name="ProfOrgCr iteriaID" msdata:ReadOnly ="true" msdata:AutoIncr ement="true" type="xs:int" />
<xs:element name="ProfOrgCr iteriaCode" type="xs:string " />
<xs:element name="ProfOrgCr iteriaDescr" type="xs:string " />
<xs:element name="CourseCri teriaID" msdata:ReadOnly ="true" msdata:AutoIncr ement="true" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="dtsCourse Criterias3Key1" msdata:PrimaryK ey="true">
<xs:selector xpath=".//mstns:procWebSe lectCourseCrite riaForSyllabus" />
<xs:field xpath="mstns:Pr ofOrgCriteriaID " />
<xs:field xpath="mstns:Co urseCriteriaID" />
</xs:unique>
<xs:unique name="Constrain t1" msdata:PrimaryK ey="true">
<xs:selector xpath=".//mstns:Table" />
<xs:field xpath="mstns:Pr ofOrgCriteriaID " />
<xs:field xpath="mstns:Co urseCriteriaID" />
</xs:unique>
</xs:element>
</xs:schema>[/HTML]

-----------------------------------------

VB.NET Code:


Expand|Select|Wrap|Line Numbers
  1. Public Class CourseCriteriaGrid
  2.     Inherits System.Web.UI.UserControl
  3.  
  4. #Region " Web Form Designer Generated Code "
  5.  
  6.     'This call is required by the Web Form Designer.
  7.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  8.         Dim configurationAppSettings As System.Configuration.AppSettingsReader = New System.Configuration.AppSettingsReader
  9.         Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
  10.         Me.sqlSelectCourseCriteria = New System.Data.SqlClient.SqlCommand
  11.         Me.SqlCommandAddCourseCriteria = New System.Data.SqlClient.SqlCommand
  12.         Me.DtsCourseCriterias31 = New UniversalSyllabus.dtsCourseCriterias3
  13.         Me.SqlDataAdapterCourseCriteria = New System.Data.SqlClient.SqlDataAdapter
  14.         Me.sqlCommandDeleteCourseCriteria = New System.Data.SqlClient.SqlCommand
  15.         CType(Me.DtsCourseCriterias31, System.ComponentModel.ISupportInitialize).BeginInit()
  16.         '
  17.         'SqlConnection1
  18.         '
  19.         Me.SqlConnection1.ConnectionString = CType(configurationAppSettings.GetValue("SqlConnection1.ConnectionString", GetType(System.String)), String)
  20.         '
  21.         'sqlSelectCourseCriteria
  22.         '
  23.         Me.sqlSelectCourseCriteria.CommandText = "[procWebSelectCourseCriteriaForSyllabus]"
  24.         Me.sqlSelectCourseCriteria.CommandType = System.Data.CommandType.StoredProcedure
  25.         Me.sqlSelectCourseCriteria.Connection = Me.SqlConnection1
  26.         Me.sqlSelectCourseCriteria.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
  27.         Me.sqlSelectCourseCriteria.Parameters.Add(New System.Data.SqlClient.SqlParameter("@CourseCode", System.Data.SqlDbType.VarChar, 20))
  28.         '
  29.         'SqlCommandAddCourseCriteria
  30.         '
  31.         Me.SqlCommandAddCourseCriteria.CommandText = "[procWebInsertCourseCriteria]"
  32.         Me.SqlCommandAddCourseCriteria.CommandType = System.Data.CommandType.StoredProcedure
  33.         Me.SqlCommandAddCourseCriteria.Connection = Me.SqlConnection1
  34.         Me.SqlCommandAddCourseCriteria.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
  35.         Me.SqlCommandAddCourseCriteria.Parameters.Add(New System.Data.SqlClient.SqlParameter("@CourseCode", System.Data.SqlDbType.VarChar, 20))
  36.         Me.SqlCommandAddCourseCriteria.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ProfOrgCriteriaID", System.Data.SqlDbType.Int, 4))
  37.         '
  38.         'DtsCourseCriterias31
  39.         '
  40.         Me.DtsCourseCriterias31.DataSetName = "dtsCourseCriterias3"
  41.         Me.DtsCourseCriterias31.EnforceConstraints = False
  42.         Me.DtsCourseCriterias31.Locale = New System.Globalization.CultureInfo("en-US")
  43.         '
  44.         'SqlDataAdapterCourseCriteria
  45.         '
  46.         Me.SqlDataAdapterCourseCriteria.SelectCommand = Me.sqlSelectCourseCriteria
  47.         '
  48.         'sqlCommandDeleteCourseCriteria
  49.         '
  50.         Me.sqlCommandDeleteCourseCriteria.CommandText = "[procWebDeleteCourseCriteria]"
  51.         Me.sqlCommandDeleteCourseCriteria.CommandType = System.Data.CommandType.StoredProcedure
  52.         Me.sqlCommandDeleteCourseCriteria.Connection = Me.SqlConnection1
  53.         Me.sqlCommandDeleteCourseCriteria.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
  54.         Me.sqlCommandDeleteCourseCriteria.Parameters.Add(New System.Data.SqlClient.SqlParameter("@CourseCriteriaID", System.Data.SqlDbType.Int, 4))
  55.         CType(Me.DtsCourseCriterias31, System.ComponentModel.ISupportInitialize).EndInit()
  56.  
  57.     End Sub
  58.  
  59.     Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
  60.     '  Protected WithEvents DtsCourseCriterias1 As UniversalSyllabus.dtsCourseCriterias3
  61.     Protected WithEvents sqlSelectCourseCriteria As System.Data.SqlClient.SqlCommand
  62.     Protected WithEvents SqlCommandAddCourseCriteria As System.Data.SqlClient.SqlCommand
  63.     Protected WithEvents DtsCourseCriterias31 As UniversalSyllabus.dtsCourseCriterias3
  64.     Protected WithEvents SqlDataAdapterCourseCriteria As System.Data.SqlClient.SqlDataAdapter
  65.     Protected WithEvents Label1 As System.Web.UI.WebControls.Label
  66.     Protected WithEvents dataGridCriteria As System.Web.UI.WebControls.DataGrid
  67.     Protected WithEvents buttonAddCriteria As System.Web.UI.WebControls.Button
  68.     Protected WithEvents sqlCommandDeleteCourseCriteria As System.Data.SqlClient.SqlCommand
  69.  
  70.     'NOTE: The following placeholder declaration is required by the Web Form Designer.
  71.     'Do not delete or move it.
  72.     Private designerPlaceholderDeclaration As System.Object
  73.  
  74.     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
  75.         'CODEGEN: This method call is required by the Web Form Designer
  76.         'Do not modify it using the code editor.
  77.         InitializeComponent()
  78.     End Sub
  79.  
  80. #End Region
  81.  
  82.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  83.  
  84.  
  85.     End Sub
  86.  
  87.     Public Sub RefreshDataCriteria()
  88.         Me.DtsCourseCriterias31.Clear()
  89.         Me.sqlSelectCourseCriteria.Parameters("@CourseCode").Value = Session("CourseCode")
  90.         Me.SqlDataAdapterCourseCriteria.Fill(Me.DtsCourseCriterias31)
  91.         Me.dataGridCriteria.DataBind()
  92.  
  93.     End Sub
  94.  
  95.     Public Event addCriteria()
  96.  
  97.  
  98.     Private Sub buttonAddCriteria_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonAddCriteria.Click
  99.         RaiseEvent addCriteria()
  100.  
  101.     End Sub
  102.  
  103.     Private Sub dataGridCriteria_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
  104.         'Enable javascript to alert about the delete
  105.         If e.Item.ItemType <> ListItemType.Header And _
  106.         e.Item.ItemType <> ListItemType.Footer And e.Item.ItemType <> ListItemType.Pager Then
  107.             Dim deleteButton2 As LinkButton = e.Item.Cells(2).Controls(0)
  108.             deleteButton2.Attributes("onclick") = "javascript:return " & _
  109.             "confirm('Are you sure you want to delete Course Criteria: " & _
  110.             DataBinder.Eval(e.Item.DataItem, "CriteriaDescription") & " ?')"
  111.         End If
  112.  
  113.     End Sub
  114.  
  115.  
  116.     Private Sub dataGridCriteria_PageIndexChanged(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
  117.         Me.dataGridCriteria.CurrentPageIndex = e.NewPageIndex
  118.         RefreshDataCriteria()
  119.     End Sub
  120.  
  121.  
  122.     Private Sub dataGridCriteria_ItemCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
  123.         Select Case (CType(e.CommandSource, LinkButton)).CommandName
  124.             Case "Delete"
  125.                 Me.sqlCommandDeleteCourseCriteria.Parameters("@CourseCriteriaID").Value = Me.dataGridCriteria.DataKeys(e.Item.ItemIndex)
  126.                 Me.SqlConnection1.Open()
  127.                 Me.sqlCommandDeleteCourseCriteria.ExecuteNonQuery()
  128.                 Me.SqlConnection1.Close()
  129.  
  130.                 Me.dataGridCriteria.EditItemIndex = -1
  131.  
  132.                 If Me.dataGridCriteria.CurrentPageIndex >= 1 And Me.dataGridCriteria.Items.Count = 1 Then
  133.                     Me.dataGridCriteria.CurrentPageIndex = Me.dataGridCriteria.CurrentPageIndex - 1
  134.  
  135.                 End If
  136.  
  137.                 RefreshDataCriteria()
  138.         End Select
  139.     End Sub
  140.  
  141.  
  142. End Class
-------------------------------------

Thank you!,
NMM
May 20 '07 #1
5 2885
kenobewan
4,871 Recognized Expert Specialist
Sounds like you have a postback problem.
May 20 '07 #2
nmm32
9 New Member
I have added the code..
Expand|Select|Wrap|Line Numbers
  1. Private Sub Page_Load
  2. (ByVal sender As System.Object, ByVal e As  System.EventArgs) Handles MyBase.Load
  3.  
  4.         If Not IsPostBack Then
  5.             RefreshDataCriteria()
  6.         End If
  7.     End Sub
But still does not work.
I even have tried it without the "if not ispostback".
May 20 '07 #3
Abdul Haque
17 New Member
try debugging the value which is being send to SP. It appear that datatype is mismatching as a result the where condition is not showing a result , which in turn is null.
May 21 '07 #4
nmm32
9 New Member
try debugging the value which is being send to SP. It appear that datatype is mismatching as a result the where condition is not showing a result , which in turn is null.
Thanks. I tried that, but it is passing the correct data.
Ok, I solved the problem, but not with the DataGrid. I chose a different control (ListBox) and arranged the programming so that the ListBox, with two buttons, can do the same thing that the DataGrid was supposed to do. Not a "pretty" box, but well, they must get along with it now.

....I have not yet figured out what happened with the DataGrid. Someone told me to call the method Me.DataBind in Page Load(). .. got to check that out.
May 21 '07 #5
Plater
7,872 Recognized Expert Expert
Anytime you change the .DataSource property, you must also call the .DataBind() function to complete the change.
I only use a few lines of code for it.
Expand|Select|Wrap|Line Numbers
  1. DataTable dt=globalDBFunctions.GetMyData();
  2. Mygridview.DataSource=dt;
  3. Mygridview.DataBind();
  4.  
May 21 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
446
by: Randy Fraser | last post by:
Is anyone using a datagrid for data entry? All I am trying to do is create a grid where the user enters an Item Number and the rest of the grid displays the information such as Description. Is anyone else doing this? If so, I would love it if you could point me in the right direction.
2
1414
by: Ray Booysen | last post by:
Hi all I have a collection of Invoices that I bind to a datagrid. Some of these invoices have been processed and you can tell this via a property in the invoice class called DateProcessed. If an invoice has been processed I do not want a button to display for this invoice but all other unprocessed invoices need the button to be displayed. Any ideas?
2
1462
by: marty | last post by:
I did some searchs, but can't find the answer to my problems. I have a editable DataGrid. I do an update of one of the rows. Postback "OnUpdateCommand" Call Oracle proc to do that actual update, which in turn creates a new row (effective dating). Call BindGrid which retrieves the rows and binds the data to the grid again.
0
1873
by: Sridhar | last post by:
Hi, I have a Crystal Report which has two sub reports in it. When I try to view this Crystal Report in my local computer, it is showing data for sub reports also. But when I deploy it to the web server and view the Crystal Report I am not able to view the data of sub reports. It is not giving any error. It is not showing the data. I checked the dlls of Crystal Report. Both the local host and server has same versions. I am not knowing...
2
1260
by: teo | last post by:
I have Datagrid on an aspx page. The datagrid has data distribued on several page (that is it has navigation buttons). Question: After the data are displayed on the Datagrid, all the data are saved on the Cache (= Temporary Internet File folder), so the user can see them offline?
0
1776
by: cms3023 | last post by:
I have a DataGrid which displays data with the aid of a procedure. I have tested the procedure inside the database and it is working fine. The table inside the database has data that matches with the parameter. I have another procedure which adds another row to the table, which is working fine inside the programming, and in the database. However, I still cannot figure out what am I doing wrong with the DataGrid configurations OR...
0
1571
by: mvanroshum | last post by:
Hi, I have the following problem: The DataSource of a DataGrid can be set to an IList. The DataGrid nicely lists the objects in the IList, showing all the public properties of the objects as the columns of the datagrid... The public properties with a primitive type are shown The public properties with userdefined types are also shown, using the eventually overridden ToString method.
4
2569
by: =?Utf-8?B?UmludSBHb3BhbGFrcmlzaG5hIFBpbGxhaQ==?= | last post by:
Hi All, I have an application that fetch data thru a store proc and display in a datagrid, but after successful execution of proc the data grid is not visible.Please go thru the following code and plz let me know what is missing.The data grid propertiy "Visible is true". try { OracleDataAccess oracleDA = new OracleDataAccess("Data
1
1912
by: chandan | last post by:
Hi All! How to Export Datagrid view data to excel in ASP.net 3.5? Thanks, Chandan
0
9846
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10890
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10581
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10279
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9416
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7007
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5855
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4479
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4053
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.