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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display true/false bit field as a checkbox on non-editable data grid?

Status
Not open for further replies.

shankel

MIS
May 19, 2003
37
US
Hello,
I have an asp.net page that is written in vb.net and html.
I use a non-editable data grid to display the results from stored procedures coming from a SQL 2000 box. One of the columns is a bit field that currently shows up on the web page as True or False. How can I have it display as either a checked or unchecked checkbox?

Thanks
 
PLease post ur code

George Oakes
Goakes@TiresPlus.com = Programmer
George@1-Specialday.com = Mobile DJ
 
<%@ Page Language=&quot;VB&quot; %>
<%@ import Namespace=&quot;System.Data&quot; %>
<%@ import Namespace=&quot;System.Data.SqlClient&quot; %>
<script runat=&quot;server&quot;>

Public strViewString As String

Sub SetData

'Connection Setup
Dim strConnection As String = ConfigurationSettings.AppSettings(&quot;QView&quot;)
Dim objConnection As New SqlConnection(strConnection)

'DataAdapter Setup
Dim strSQL As string = &quot;spApplication&quot;
Dim objAdapter As New SqlDataAdapter(strSQL, objConnection)

'DataSet & Adapter & Table
Dim objDataSet As New DataSet()
objAdapter.Fill (objDataSet, &quot;dtApplications&quot;)
Dim dtApplications As DataTable = objDataSet.Tables(&quot;dtApplications&quot;)

'Create DataView on dtApplications
Dim dvView As New DataView (dtApplications)
dvView.Sort = strViewString

'Bind data
DataGrid1.DataSource = dvView
DataGrid1.DataBind()
End Sub

Sub Page_Load(Source As Object, E As EventArgs)
If Not Page.IsPostBack Then
strViewString = &quot;Application Name&quot;
SetData()
End if
End Sub

Sub SortColumn(Source As Object, E As DataGridSortCommandEventArgs)
If E.SortExpression = &quot;Platform&quot; Then
strViewString = &quot;Platform&quot;
Else
strViewString = E.SortExpression
End If
SetData()
End Sub

</script>

<form runat=&quot;server&quot;>
<asp:datagrid id=&quot;DataGrid1&quot; runat=&quot;server&quot; OnSortCommand=&quot;SortColumn&quot; AllowSorting=&quot;True&quot; CellPadding=&quot;5&quot; CellSpacing=&quot;0&quot; Font-Size=&quot;14px&quot;>
<HeaderStyle font-bold=&quot;True&quot; forecolor=&quot;White&quot; backcolor=&quot;#4A3C8C&quot;></HeaderStyle>
<ItemStyle backcolor=&quot;#DEDFDE&quot;></ItemStyle>
</asp:datagrid>
</form>
 
Code:
<asp:datagrid id=&quot;DataGrid1&quot; runat=&quot;server&quot;>
  <Columns>
    <asp:TemplateColumn>
      <ItemTemplate>
        <asp:CheckBox runat=server Checked='<%#  Convert.ToBoolean(DataBinder.Eval(Container.DataItem, &quot;bitField&quot;)) %>' />
      </ItemTemplate>
    </asp:TemplateColumn>
  </Columns>
</asp:datagrid>
 
I'm almost there. I now have an additional column that is showing checkboxes, and everything in the SOX column that is true is showing a checked box in the noname column.
How would I substitute the SOX column with this column and label it SOX. Also, prevent the checkboxes from being changed from the website?
 
The simple and visual way is to select the DataGrid in properties, click the browse button of the column collection, then manipulate the header text property.

You can simply add Enabled=&quot;false&quot; inside the <asp:CheckBox ...> in the ItemTemplate to make it non-selectable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top