Link to home
Start Free TrialLog in
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

Avatar of CtrlAltDl
CtrlAltDl
Flag of United States of America image

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
Here is a little sample code:
  <asp:TemplateField HeaderText="Roles">
      <ItemTemplate>
        <asp:CheckBox ID="chkDelete" runat="server" />
     </ItemTemplate>
   </asp:TemplateField>

Open in new window

Avatar of harveygs
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?
from database do like this

if databasevalue = "True" Then
chkDelete.Checked = true
Else
chkDelete.Checked = false
where does that go in my code listed above ? thanks
sorry , i think this will not implement in your case
As long as your values are true/false then you just do this:

<asp:CheckBox ID="chkDelete" runat="server" Checked='<%# Bind("AllowView") %>' />
error was :=
DataBinding: 'System.Collections.Hashtable' does not contain a property with the name 'AllowView'
You have to use the field name of your data, which I think is PR_default, correct?
ASKER CERTIFIED SOLUTION
Avatar of CtrlAltDl
CtrlAltDl
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
tried that but i think its working with :-
<asp:CheckBox ID="chkDelete" runat="server" Checked=<%#container.value%>  />

going home test further tomorrow.

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