Having Lot Of Problems With DataGrid!!!!!

Results 1 to 2 of 2

Thread: Having Lot Of Problems With DataGrid!!!!!

  1. #1
    Join Date
    Dec 1969

    Default Having Lot Of Problems With DataGrid!!!!!

    The following code retrieves records from a SQL Server DB table & these records are being used in another SQL query. Also I am creating a DataGrid programmatically & binding it to the DataSource. Finally the records retrieved will be displayed in this DataGrid.<BR><BR>&#060;script language="VB" runat="server"&#062;<BR>Sub Page_Load(obj As Object,ea As EventArgs)<BR>strSQL1="SELECT DISTINCT(ErnCode) FROM ALLV ORDER BY ErnCode"<BR>objConn=New SQLConnection("Server=(local);Database=DBName;UID= sa;PWD=")<BR>objDapter1=New SQLDataAdapter(strSQL1,objConn)<BR>objDapter1.Fill (dTable)<BR>objDapter1.Dispose()<BR> <BR>Dim strSQL2 As New StringBuilder("SELECT DISTINCT(em.ECode),em.EName,")<BR>For Each dRow In dTable.Rows<BR>strErnCode=dRow.Item(0).ToString<BR >strSQL2.Append("(SELECT SUM(allv.Amt) FROM ALLV AS allv WHERE allv.ErnCode=&#039;")<BR>strSQL2.Append(strErnCode )<BR>strSQL2.Append("&#039; AND em.ECode=allv.ECode AND MONTH(allv.Date)=4) AS ")<BR>strSQL2.Append(strErnCode)<BR>strSQL2.Append (",")<BR>Next<BR>strSQL2.Append(" FROM EMST AS em,ALLV AS allv WHERE em.ECode=allv.ECode")<BR>strSQL2.Replace(", FROM"," FROM")<BR> <BR>objDapter2=New SQLDataAdapter(strSQL2.ToString,objConn)<BR>objDS= New DataSet()<BR>objDapter2.Fill(objDS,"EVSummary")<BR >objDapter2.Dispose()<BR>dGrid.DataSource=objDS.Ta bles("EVSummary").DefaultView<BR>dGrid.DataBind()< BR><BR>mainPlaceHolder.Controls.Add(dGrid)<BR>.... ..................<BR>End Sub<BR>&#060;/script&#062;<BR>......................<BR>&#060;as p:PlaceHolder id="mainPlaceHolder" runat="server"/&#062;<BR>......................<BR><BR>Please note that in the above code, I am not using HeaderText or TemplateColumn or BoundColumn. Also note that all the column names except for ECode & EName in strSQL2 are being generated dynamically. The above code displays the records as I want but I am still facing a petty problem. The problem is since I am not using any HeaderText in the above code, when viewed by the users, the HTML table will show the header in the 1st column as ECode, the header in the 2nd column will be displayed as EName. All I want to do is, instead of displaying the headers as ECode & EName, I want that these 2 headers should be displayed as EMPLOYEE CODE & EMPLOYEE NAME respectively in the HTML table which the users will ultimately view. How do I do this?<BR><BR>Thanks,<BR><BR>Arpan

  2. #2
    Join Date
    Dec 1969

    Default RE: Having Lot Of Problems With DataGrid!!!!!

    When having the Datagrid autogenerate the columns, the header of each column is the name returned from the SQL statement. In your SQL statement use AS to specify a different name than the field name. So, something like SELECT ECode AS &#039;EMPLOYEE CODE&#039;*, EName AS &#039;EMPLOYEE NAME&#039; FROM ...<BR><BR>* the single quotes can be single quotes, double quotes or square brackets in SQL Server. I do not recall which is the ANSI SQL standard for this.<BR><BR>O&#039;Cary<BR>www.ocary.com

Posting Permissions

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