Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 13th, 2004, 01:08 PM
Registered User
 
Join Date: Dec 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Radiobuttonlist in datalist edititemtemplate

I'm having trouble trying to pre-select a yes/no value in a radiobuttonlist in the edititemtemplate
section based on a true/false database value.

I can't seem to be able to reference the radiobuttonlist control using find control.

<script language="vb" runat="server">
    Dim strConnection As String ="Provider=Microsoft.Jet.OLEDB.4.0;data source=d:\webapps\integration\database\integration _test_request.mdb"
    Dim objConnection As New OleDbConnection(strConnection)

..
..

Sub BindTaskDetailGrid()

    Dim strSQL2 as String = "SELECT Applications.Integration_Tested, Test_Request.GRADS_Class_Changed, Test_OS.TestOSID "
        strSQL2 += "FROM (Applications INNER JOIN Test_Request ON Applications.AppID = Test_Request.AppID) INNER JOIN Test_OS "
         strSQL2 += "ON Test_Request.RequestID = Test_OS.RequestID WHERE Test_OS.TestOSID=99;"

' Create the commandand set it's properties

    'Set the datagrid's datasource to the datareader and databind
    Dim TaskDataSet as New DataSet()
    Dim TaskDataAdapter as OleDbDataAdapter = New OleDbDataAdapter(strSQL2, objConnection)
    TaskDataAdapter.Fill(TaskDataSet,"theTable")

    TaskDetail.DataSource = TaskDataSet

..
..

End Sub

</script>

<html>

..
..



<asp:datalist id="TaskDetail" runat="server"
OnEditCommand="TaskDetail_Edit"
OnItemDataBound="TaskDetail_ItemDataBound"
..
..


<EditItemTemplate>
    <asp:radiobuttonlist id="IntegrationTested" runat="server" >
        <asp:listitem id ="TestedYes" runat="server" value="True" text="Yes" />
        <asp:listitem id ="TestedNo" runat="server" value="False" text="No" />
    </asp:radiobuttonlist>
</EditItemTemplate>
 
Old December 13th, 2004, 04:28 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I created a quick table in my DB with 2 columns first col is a descrition char(10) the second is a bit, basically 0 = False, 1 = True. My datagrid contains 2 columns. The first shows the description, and the second is a template column with 2 RadioButtons, rb1(True) and rb2(False). I then filled a dataset and bound it to my datagrid. Here is the code behind for the ItemDataBound Event:

   Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
        ' Response.Write(e.Item.ItemIndex)
        If e.Item.ItemIndex <> -1 Then
            Response.Write(DsTest1.Tables(0).Rows(e.Item.ItemI ndex).Item(1))
        End If


        If e.Item.ItemIndex <> -1 And e.Item.Cells(1).HasControls Then
            If DsTest1.Tables(0).Rows(e.Item.ItemIndex).Item(1) = True Then ''this column is actually a bit in the DB .. but use True or False for comparison here
                CType(e.Item.Cells(1).FindControl("rb1"), RadioButton).Checked = True
            Else
                CType(e.Item.Cells(1).FindControl("rb2"), RadioButton).Checked = True
            End If
        End If
    End Sub

 
Old December 13th, 2004, 04:47 PM
Registered User
 
Join Date: Dec 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by jbenson001
 I created a quick table in my DB with 2 columns first col is a descrition char(10) the second is a bit, basically 0 = False, 1 = True. My datagrid contains 2 columns. The first shows the description, and the second is a template column with 2 RadioButtons, rb1(True) and rb2(False). I then filled a dataset and bound it to my datagrid. Here is the code behind for the ItemDataBound Event:

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
        ' Response.Write(e.Item.ItemIndex)
        If e.Item.ItemIndex <> -1 Then
            Response.Write(DsTest1.Tables(0).Rows(e.Item.ItemI ndex).Item(1))
        End If


        If e.Item.ItemIndex <> -1 And e.Item.Cells(1).HasControls Then
            If DsTest1.Tables(0).Rows(e.Item.ItemIndex).Item(1) = True Then ''this column is actually a bit in the DB .. but use True or False for comparison here
                CType(e.Item.Cells(1).FindControl("rb1"), RadioButton).Checked = True
            Else
                CType(e.Item.Cells(1).FindControl("rb2"), RadioButton).Checked = True
            End If
        End If
    End Sub

How would you code this for a datalist?
 
Old December 13th, 2004, 04:56 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I don't use datalists actually, but the syntax should be the same as far as I can see. Give it a try.

 
Old December 13th, 2004, 05:08 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Code for DataList


   Private Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound

        If e.Item.ItemIndex <> -1 And e.Item.HasControls Then
            If DsTest1.Tables(0).Rows(e.Item.ItemIndex).Item(1) = True Then ''this column is actually a bit in the DB .. but use True or False for comparison here
                CType(e.Item.FindControl("rb1"), RadioButton).Checked = True
            Else
                CType(e.Item.FindControl("rb2"), RadioButton).Checked = True
            End If
        End If
    End Sub

 
Old December 13th, 2004, 06:40 PM
Registered User
 
Join Date: Dec 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I get the following error:
Object reference not set to an instance of an object
 
Old December 14th, 2004, 12:47 PM
Registered User
 
Join Date: Dec 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This did the trick:

Sub TaskDetail_ItemDataBound(sender as Object, e as DataListItemEventArgs)

If TaskDetail.EditItemIndex <> -1 And e.Item.ItemIndex <> -1 And e.Item.HasControls Then
If TaskDataSet.Tables(0).Rows(e.Item.ItemIndex).Item( 1) = True Then
     CType(e.Item.FindControl("IntegrationTested_Radi olist"), RadioButtonList).SelectedIndex = 1
            Else
                CType(e.Item.FindControl("IntegrationTested_Radiol ist"), RadioButtonList).SelectedIndex = 0
            End If
        End If


End Sub

Thanks for the help.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Datalist-edititemtemplate-RadioButtonList cp75 ASP.NET 1.0 and 1.1 Basics 1 September 1st, 2006 12:56 PM
strange problem with EditItemTemplate hertendreef ASP.NET 2.0 Professional 0 August 17th, 2006 08:44 AM
radiobuttonlist in a paging datalist burchbt Pro VB.NET 2002/2003 2 August 13th, 2004 09:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.