zachvaldez
asked on
itemTemplate within a Gridview not displaying in run mode
I could not figure out why the itemtemplate for chkbox ID = "Lunch" column is not displaying.The chkbox Id = "Select" column is displaying.
thanks >
Here's the source
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False " Width="592px" style="left: 7px; position: relative; top: 5px">
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID ="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Button" CausesValidation="False" ShowSelectButton="True" />
<asp:TemplateField HeaderText="Lunch">
<ItemTemplate>
<asp:CheckBox ID ="chkLunch" runat="server" Enabled="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="MASTERID" HeaderText="ID" />
<asp:BoundField DataField="FULLNAME" HeaderText="FullName" />
<asp:BoundField DataField="CATEGORY" HeaderText="Category" />
</Columns>
<AlternatingRowStyle BackColor="Azure" />
</asp:GridView></form>
thanks >
Here's the source
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID ="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Button" CausesValidation="False" ShowSelectButton="True" />
<asp:TemplateField HeaderText="Lunch">
<ItemTemplate>
<asp:CheckBox ID ="chkLunch" runat="server" Enabled="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="MASTERID" HeaderText="ID" />
<asp:BoundField DataField="FULLNAME" HeaderText="FullName" />
<asp:BoundField DataField="CATEGORY" HeaderText="Category" />
</Columns>
<AlternatingRowStyle BackColor="Azure" />
</asp:GridView></form>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just a quick guess (haven't tested it yet). What if you do:
If dr.HasRows Then
GridView1.DataSource = dr
GridView1.DataBind()
End If
I am heading off home and will check back tomorrow if you still have trouble.
If dr.HasRows Then
GridView1.DataSource = dr
GridView1.DataBind()
End If
I am heading off home and will check back tomorrow if you still have trouble.
ASKER
First, because of the datasource, there is conflict with this...
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=myServer;Initial Catalog=Northwind;Integrat ed Security=True"
ProviderName="System.Data. SqlClient" SelectCommand="SELECT EmployeeID, FirstName, LastName FROM Employees">
</asp:SqlDataSource>
MY main concern is why can't i display the lunch itemtemplate in the grid...
thanks for your help.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=myServer;Initial Catalog=Northwind;Integrat
ProviderName="System.Data.
</asp:SqlDataSource>
MY main concern is why can't i display the lunch itemtemplate in the grid...
thanks for your help.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I don't understand why you have to manually add those fields again if you have those fields already defined in your GridView. Your code will append duplicated columns to the GridView. See the attached screen shot.>>>> YOU"RE ABSOLUTELY CORRECT!!
Also, there was this code that removes the columns and repopulate it. Between those two, I am losing the column for the "lunch"
I appreciate your help. Now I'll try to figure out how to insert the rows selected to the " Event" table.
Also, there was this code that removes the columns and repopulate it. Between those two, I am losing the column for the "lunch"
I appreciate your help. Now I'll try to figure out how to insert the rows selected to the " Event" table.
ASKER
If dr.HasRows Then
Dim bf As New BoundField
bf.HeaderText = "ID"
bf.HeaderStyle.BackColor = Drawing.Color.PowderBlue
bf.DataField = "MASTERID"
bf.ItemStyle.Width = "80"
GridView1.Columns.Add(bf)
Dim bf2 As New BoundField
bf2.HeaderText = "Name"
bf2.HeaderStyle.BackColor = Drawing.Color.PowderBlue
bf2.DataField = "FULLNAME"
bf2.ItemStyle.Width = "200"
GridView1.Columns.Add(bf2)
Dim bf3 As New BoundField
bf3.HeaderText = "Category"
bf3.HeaderStyle.BackColor = Drawing.Color.PowderBlue
bf3.DataField = "CATEGORY"
bf3.ItemStyle.Width = "300"
GridView1.Columns.Add(bf3)
GridView1.DataSource = dr
GridView1.DataBind()
End If