Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datagrids

Status
Not open for further replies.

sthmpsn1

MIS
Sep 26, 2001
456
US
Does a datagrid have to display every field from the table in my database or can I select whichone's to include. I have this code below. When I set AutoGeneratecolumns="False" the page comes back blank, but when I set it to true my page displays correctly. What am I missing????

<asp:DataGrid id=&quot;PersonInfo&quot; Runat=&quot;server&quot;
AllowSorting=&quot;True&quot;
DataKeyField=&quot;ID&quot;
AlternatingItemStyle-BackColor=&quot;#A6F4FD&quot;
AutoGeneratecolumns=&quot;False&quot; />
<columns>
<asp:boundcolumn
DataField=&quot;ID&quot;
HeaderText=&quot;ID&quot;
ReadOnly=&quot;true&quot;
SortExpression=&quot;ID&quot; />
<asp:boundcolumn
DataField=&quot;loginID&quot;
HeaderText=&quot;Login ID&quot;
SortExpression=&quot;loginID&quot; />
<asp:boundcolumn
DataField=&quot;vacationtime&quot;
HeaderText=&quot;Vacation Time&quot;
SortExpression=&quot;vacationtime&quot; />
<asp:boundcolumn
DataField=&quot;overtime&quot;
HeaderText=&quot;Over Time&quot;
SortExpression=&quot;overtime&quot; />
<asp:boundcolumn
DataField=&quot;medicalleave&quot;
HeaderText=&quot;Medical Leave&quot;
SortExpression=&quot;medicalleave&quot; />
<asp:boundcolumn
DataField=&quot;volunteertime&quot;
HeaderText=&quot;Volunteer Time&quot;
SortExpression=&quot;volunteertime&quot; />
<asp:boundcolumn
DataField=&quot;personalTime&quot;
HeaderText=&quot;Personal Time&quot;
SortExpression=&quot;personalTime&quot; />
<asp:boundcolumn
DataField=&quot;extendedtime&quot;
HeaderText=&quot;Extended Time&quot;
SortExpression=&quot;extendedtime&quot; />

</columns>
</asp:DataGrid>
 
If you set the autogenerate to false you need to explictly set the columns yourself. Follow what you have there with the autogenerate to false. That'l do donkey, that'l do
[bravo] Mark
 
what I have above doesn't display anything. Do I need the <columns> tag in between each <asp:boundcolumn> tag or am I not understanding you?
 
This is what I have for a autogeneratecolumns=false datagrid. then in my code I fill the dataset and use the grids .databind() property and things are wonderful

<asp:DataGrid id=DataGrid1 style=&quot;Z-INDEX: 105; LEFT: 273px; POSITION: absolute; TOP: 33px&quot; runat=&quot;server&quot; DataSource=&quot;<%# DataSet11 %>&quot; DataMember=&quot;RateSite&quot; AutoGenerateColumns=&quot;False&quot;>
<Columns>
<asp:BoundColumn DataField=&quot;EffectiveDate&quot; HeaderText=&quot;EffectiveDate&quot;></asp:BoundColumn>
<asp:BoundColumn DataField=&quot;Rate&quot; HeaderText=&quot;Rate&quot;></asp:BoundColumn>
<asp:BoundColumn DataField=&quot;RateTypeID&quot; HeaderText=&quot;RateTypeID&quot;></asp:BoundColumn>
<asp:BoundColumn DataField=&quot;SubClassID&quot; HeaderText=&quot;SubClassID&quot;></asp:BoundColumn>
</Columns>
</asp:DataGrid> That'l do donkey, that'l do
[bravo] Mark
 
Okay well I modified your code mark like this

<asp:DataGrid id=DataGrid1 style=&quot;Z-INDEX: 105; LEFT: 273px; POSITION: absolute; TOP: 33px&quot; runat=&quot;server&quot; DataSource=&quot;<%# empDS.Tables(&quot;timeoffbene&quot;) %>&quot; DataMember=&quot;Timeoffbene&quot; AutoGenerateColumns=&quot;False&quot;>
<Columns>
<asp:BoundColumn DataField=&quot;loginID&quot; HeaderText=&quot;EffectiveDate&quot;></asp:BoundColumn>
<asp:BoundColumn DataField=&quot;volunteertime&quot; HeaderText=&quot;Rate&quot;></asp:BoundColumn>
<asp:BoundColumn DataField=&quot;personalTime&quot; HeaderText=&quot;RateTypeID&quot;></asp:BoundColumn>
<asp:BoundColumn DataField=&quot;vacationtime&quot; HeaderText=&quot;SubClassID&quot;></asp:BoundColumn>
</Columns>
</asp:DataGrid>

I get a &quot;The server tag is not well formed.&quot; Error on it. also I am pulling information from a dataset called empDS. is the way I am doing it in my modified code correct??

 
I guess I am just confused because I have this subroutine here

Public Sub BindData( strSortField As String)
'Dim myDataSet as New DataSet
'Dim mySqlDataAdapter as SqlDataAdapter
'mySqlDataAdapter = New SqlDataAdapter( _
'&quot;SELECT ID, loginID, overtime, medicalleave, volunteertime, personalTime, extendedtime FROM timeoffbene Order by loginID&quot;, _
'&quot;server=AM1ST_FS1;database=HRINFO;uid=sa;&quot;)
Dim dbconn As SqlConnection = New SqlConnection(&quot;server=AM1ST_FS1;database=HRINFO;uid=sa;&quot;)
Dim selectCMD As SqlCommand = New SqlCommand()
Dim selectCMD1 As SqlCommand = New SqlCommand()

selectCMD.CommandText = &quot;SELECT ID, loginID, overtime, medicalleave, vacationTime, volunteertime, personalTime, extendedtime FROM timeoffbene Order by loginID&quot;
selectCMD.Connection = dbconn
selectCMD.CommandTimeout = 30
Dim empDA As SqlDataAdapter = New SqlDataAdapter
empDA.SelectCommand = selectCMD
dbconn.Open()
Dim empDS As DataSet = New DataSet
empDA.Fill(empDS, &quot;timeoffbene&quot;)
dbconn.Close()
DataGrid1.DataSource = empDS.Tables(&quot;timeoffbene&quot;).DefaultView
DataGrid1.DataBind()

End Sub
then this code here for the datagrid
<asp:DataGrid id=&quot;DataGrid1&quot; style=&quot;Z-INDEX: 105; LEFT: 273px; POSITION: absolute; TOP: 33px&quot; runat=&quot;server&quot; DataMember=&quot;Timeoffbene&quot; AutoGenerateColumns=&quot;True&quot;/>
<Columns>
<asp:BoundColumn DataField=&quot;loginID&quot; HeaderText=&quot;EffectiveDate&quot;></asp:BoundColumn>
<asp:BoundColumn DataField=&quot;volunteertime&quot; HeaderText=&quot;Rate&quot;></asp:BoundColumn>
<asp:BoundColumn DataField=&quot;personalTime&quot; HeaderText=&quot;RateTypeID&quot;></asp:BoundColumn>
<asp:BoundColumn DataField=&quot;vacationtime&quot; HeaderText=&quot;SubClassID&quot;></asp:BoundColumn>
</Columns>
</asp:DataGrid>

if I set that too false and leave datasource=&quot;whatever&quot; out then it doesn't work. I don't understand why I need that because I am binding data when the page loads.
 
sigh.. no your not. From your top code IC that you aren't useing absolute positioning but flow. Also the datasource specifies the dataset only. The datamember specifies the table.

Try this

<asp:DataGrid id=DataGrid1 runat=&quot;server&quot; DataSource=&quot;<%# empDS%>&quot; DataMember=&quot;Timeoffbene&quot; AutoGenerateColumns=&quot;False&quot;>
<Columns>
<asp:BoundColumn DataField=&quot;loginID&quot; HeaderText=&quot;EffectiveDate&quot;></asp:BoundColumn>
<asp:BoundColumn DataField=&quot;volunteertime&quot; HeaderText=&quot;Rate&quot;></asp:BoundColumn>
<asp:BoundColumn DataField=&quot;personalTime&quot; HeaderText=&quot;RateTypeID&quot;></asp:BoundColumn>
<asp:BoundColumn DataField=&quot;vacationtime&quot; HeaderText=&quot;SubClassID&quot;></asp:BoundColumn>
</Columns>
</asp:DataGrid>


That'l do donkey, that'l do
[bravo] Mark
 
You either need to set the datasource and datamember properties of the grid in your code
or
put the drag the dataset onto the design view so that it's global to the web form and use it like I have. That'l do donkey, that'l do
[bravo] Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top