Avatar of harveygs
harveygs
 asked on

show checkbox in a grid instead of true and false

I am using a obout grid in asp.net.
The grid displays true or false for the bollean value ofthe column. OK
When clicking edit it changes to a checkbox ticked or not showing the state of the true or false in the column.OK
I want it to show a checkbox all of the time instead of showing true or false whether in or out of edit mode.
also in VB not C# please.
Thanks

<%@ Page Language="VB"%>
<%@ Register TagPrefix="obout" Namespace="Obout.Grid" Assembly="obout_Grid_NET" %>
<%@ Register TagPrefix="obout" Namespace="Obout.Interface" Assembly="obout_Interface" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data.SqlClient" %>
 
<script language="VB" runat="server">
 
	</script>		
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html>
	<head>
		<title>Printer control v1</title>		
	</head>
	<body>	
		<form runat="server">					
					
		<obout:Grid id="grid1" runat="server" folderstyle="styles\premiere_blue"  pagesize="17" scrollheight="450" CallbackMode="true" Serialize="true" AutoGenerateColumns="false" datasourceID="mydatasource">
			<Columns>
				<obout:Column DataField="PC_ID" visible="false" ReadOnly="true" HeaderText="PC_ID" Width="10" runat="server"/>
				<obout:Column DataField="PC_Name" HeaderText="PC_Name" Width="100" runat="server"/>
				<obout:Column DataField="PR_ID" HeaderText="PR_ID" Width="80" runat="server"/>
				<obout:Column DataField="printer" readonly="true" HeaderText="printer" Width="250" runat="server"/>
				<obout:Column DataField="PR_default" HeaderText="PR_Default" Width="120" runat="server">
					<TemplateSettings  EditTemplateID="TemplateEditPR_Default" TemplateID="TemplatePR_Default" />
				</obout:Column>
				<obout:Column AllowEdit="true" AllowDelete="true" HeaderText="" Width="150" runat="server" />
			</Columns>
			<Templates>
				<obout:GridTemplate runat="server" ID="TemplatePR_Default" ControlID="chkPR_Default" ControlPropertyName="checked" UseQuotes="false">
					<Template>
					======	WANT CHECKBOX HERE showing state of true or false=======
					</Template>
				</obout:GridTemplate>
			
				<obout:GridTemplate runat="server" ID="TemplateEditPR_Default" ControlID="chkPR_Defaultedit" ControlPropertyName="checked" UseQuotes="false">
					<Template>
						<input type="checkbox" id="chkPR_Defaultedit">
					</Template>
				</obout:GridTemplate>			
			</Templates>
			
		</obout:Grid>
		
		<asp:SqlDataSource runat="server" ID="printerdropdown" SelectCommand="SELECT DISTINCT pr_name FROM printerlist ORDER BY pr_name ASC"
		 ConnectionString="<%$ ConnectionStrings:printerConnectionString %>"></asp:SqlDataSource>
		 
		<asp:SqlDataSource runat="server" ID="mydatasource"
			updateCommand="UPDATE PCList SET PC_Name=@PC_Name,PR_ID=@PR_ID,PR_Default=@PR_Default WHERE PC_ID = @PC_ID"
			SelectCommand="SELECT PC_ID, PC_Name,PR_ID, PR_Default,(SELECT PR_Name FROM PrinterList WHERE (PCList.PR_ID = PR_ID)) AS printer FROM PCList order by pc_name "
			Insertcommand="insert into PCList (PC_Name,PR_ID,PR_Default) values (@PC_Name,@PR_ID,@PR_Default) " 
			deletecommand="delete from pclist  where pc_id=@pc_id"
			ConnectionString="<%$ ConnectionStrings:printerConnectionString %>">
		   <InsertParameters>                
				<asp:Parameter Name="PC_Name" Type="String" />
				<asp:Parameter Name="PR_ID" Type="int16" />
				<asp:Parameter Name="PR_default" Type="boolean" />			
		    </insertParameters>
			<UpdateParameters>                
				<asp:Parameter Name="PC_Name" Type="String" />
				<asp:Parameter Name="PR_ID" Type="int16" />
				<asp:Parameter Name="PR_default" Type="boolean" />			
		    </UpdateParameters>
			<deleteParameters>                
				<asp:Parameter Name="PC_Name" Type="String" />
				<asp:Parameter Name="PR_ID" Type="int16" />
				<asp:Parameter Name="PR_default" Type="boolean" />			
		    </deleteParameters>			
		 </asp:SqlDataSource>
		
		
		</form>
	</body>
</html>

Open in new window

.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
harveygs

8/22/2022 - Mon
CtrlAltDl

Here is a great article on how to add checkboxes in a gridview, should be similar with your obout control.

http://www.asp.net/Learn/data-access/tutorial-52-vb.aspx
CtrlAltDl

Here is a little sample code:
  <asp:TemplateField HeaderText="Roles">
      <ItemTemplate>
        <asp:CheckBox ID="chkDelete" runat="server" />
     </ItemTemplate>
   </asp:TemplateField>

Open in new window

harveygs

ASKER
<asp:CheckBox ID="chkDelete" runat="server" />
this shows the checkboxes but all unchecked. Didn't say but I'm very begginer at this.
Dont need to do anything with check box just show ticked or not.

Is there any programing allowed in the template like if  <%#container.value%>  = true then checked=true or something?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
amar31282

from database do like this

if databasevalue = "True" Then
chkDelete.Checked = true
Else
chkDelete.Checked = false
harveygs

ASKER
where does that go in my code listed above ? thanks
amar31282

sorry , i think this will not implement in your case
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
CtrlAltDl

As long as your values are true/false then you just do this:

<asp:CheckBox ID="chkDelete" runat="server" Checked='<%# Bind("AllowView") %>' />
harveygs

ASKER
error was :=
DataBinding: 'System.Collections.Hashtable' does not contain a property with the name 'AllowView'
CtrlAltDl

You have to use the field name of your data, which I think is PR_default, correct?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
CtrlAltDl

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
harveygs

ASKER
tried that but i think its working with :-
<asp:CheckBox ID="chkDelete" runat="server" Checked=<%#container.value%>  />

going home test further tomorrow.

thanks
harveygs

ASKER
changed the bind bit to =<%#container.value%> it works fine.
Perhaps i'm not binding? Anyway all ok thanks.