CheckBox template always evaluate to False even if checked in a DataGrid hosted inside a TabStrip

Discussion in 'ASP .Net' started by mehul, May 3, 2004.

  1. mehul

    mehul Guest

    CheckBox template always evaluate to False even if checked in a DataGrid
    hosted inside a TabStrip in ASP.NET


    Hi,

    I am trying to develop an ASP.NET application. I am using TabStrip
    (which is part of IE WebControls).

    Inside a tab I have a datagrid defined as follows:



    <iewc:multipage id="MultiPage_Control" style="Z-INDEX: 103; LEFT: 452px;
    POSITION: absolute; TOP: 297px" tabIndex="3" runat="server"
    Height="160px" Width="458px" BorderColor="#C0C0FF" BorderStyle="Ridge"
    SelectedIndex="3">
    <IEWC:pAGEVIEW>Customers
    <DIV id="Layer6" style="WIDTH: 250px; POSITION: relative; HEIGHT: 80px">
    <asp:datagrid id="dgAssignedTo" style="Z-INDEX: 104; LEFT: 13px;
    POSITION: absolute; TOP: 17px" runat="server" BorderColor="black"
    BorderWidth="1" CellPadding="3" AutoGenerateColumns="False">
    <HeaderStyle BackColor="#00AAAA"></HeaderStyle>
    <Columns>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:CheckBox id=CheckBox1 runat="server" Checked='<%#
    DataBinder.Eval(Container.DataItem, "Active") %>'>
    </asp:CheckBox>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="Store Address">
    <ItemTemplate>
    <asp:Label ID="lblUsername" Text='<%#
    DataBinder.Eval(Container.DataItem, "Username") %>' Runat="server" />
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="Store Address">
    <ItemTemplate>
    <asp:Label ID="lblName" Text='<%#
    DataBinder.Eval(Container.DataItem, "Name") %>' Runat="server" />
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:datagrid>
    </DIV></IEWC:pAGEVIEW>
    <IEWC:pAGEVIEW></IEWC:pAGEVIEW>
    <IEWC:pAGEVIEW></IEWC:pAGEVIEW>
    <IEWC:pAGEVIEW></IEWC:pAGEVIEW>
    <IEWC:pAGEVIEW></IEWC:pAGEVIEW>
    </iewc:multipage></form>



    which is basically a datagrid which has a checkbox (1st column) and 2
    other columns
    (employee usernames).


    What i want is when the user checks a checkbox, I can save that to the
    database.



    Public Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles cmdSave.Click



    Dim myDataGridItem As DataGridItem
    Dim chkSelected As System.Web.UI.WebControls.CheckBox
    Dim strUserName As String


    conHelpdesk.Open()


    For Each myDataGridItem In dgAssignedTo.Items

    chkSelected = myDataGridItem.FindControl("CheckBox1")
    ' If chkSelected.Checked Then
    strUserName =
    CType(myDataGridItem.FindControl("lblUsername"), Label).Text
    System.Diagnostics.Debug.WriteLine(strUserName)


    strCriteria = "Update employee Set Active=@strActive " _
    & " Where Username=@strUsername"

    System.Diagnostics.Debug.WriteLine(strCriteria)
    cmdSelect4 = New SqlCommand(strCriteria, conHelpdesk)
    cmdSelect4.Parameters.Add("@strUsername", strUserName)
    cmdSelect4.Parameters.Add("@strActive", SqlDbType.Bit).Value
    = chkSelected.Checked
    cmdSelect4.ExecuteNonQuery()

    ' End If
    Next

    conHelpdesk.Close()

    End Sub



    However even if the user checks the checkbox next to the employee column
    'chkSelected'
    always evaluates to false.

    This same code when the datagrid is outside of the TabStrip executes
    fine but inside the
    TabStrip always evaluates to false.

    I have checked MSDN KB but cannt find any errors.

    Pls Help,
    Rgs,
    Mehul





    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    mehul, May 3, 2004
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RodBillett

    Always One checkbox checked

    RodBillett, Dec 4, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    1,447
    bruce barker
    Dec 4, 2003
  2. yurps
    Replies:
    1
    Views:
    7,512
    rajeshthangarasu1983
    Feb 29, 2008
  3. Eric via .NET 247

    [ASP.net / C#] Checkbox Checked Always false

    Eric via .NET 247, Mar 25, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    9,591
    dunshRB
    Mar 25, 2005
  4. VB Programmer
    Replies:
    1
    Views:
    4,650
    Ken Cox [Microsoft MVP]
    Apr 13, 2005
  5. runescience
    Replies:
    0
    Views:
    4,538
    runescience
    Feb 23, 2006
  6. Alan Silver
    Replies:
    2
    Views:
    727
    Alan Silver
    Jul 20, 2006
  7. Prescott

    Checkbox in a datagrid always returns false

    Prescott, Mar 21, 2005, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    929
    Prescott Chartier
    Mar 29, 2005
  8. Rich_C
    Replies:
    0
    Views:
    176
    Rich_C
    Aug 17, 2006
Loading...