Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET 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 October 4th, 2004, 10:51 AM
Authorized User
 
Join Date: Jun 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP.NET C# - Trouble with checkbox

Anyone know why the code below does not work. All I want is to check a checkbox, then hit a button, then for the value of the DataKeyField in the DataGrid to show up as the Text property in a Label called textboxMessage. The DataGrid is working OK as if the foreach loop, the bit where its coming unstuck is the check box definition or test to see if it is checked. I don't get a compilation error - just that it doesn't work.

<asp:DataGrid id="DataGrid1" DataKeyField="RequestID" runat="server" Font-Size="X-Small">
    <Columns>
        <asp:TemplateColumn>
        <ItemTemplate>
            <asp:CheckBox ID="checkboxSelect" Runat="server"></asp:CheckBox>
            </ItemTemplate>
        </asp:TemplateColumn>
    </Columns>

</asp:DataGrid>


private void Button1_Click(object sender, System.EventArgs e)
{

    foreach(DataGridItem DGridItem in DataGrid1.Items)
    {

    CheckBox myCheckbox = (CheckBox)DGridItem.FindControl("checkboxSelect");

    if(myCheckbox.Checked == true)
        {
    textboxMessage.Text= DataGrid1.DataKeys[DGridItem.ItemIndex].ToString();
        }
    }
}
 
Old October 5th, 2004, 11:46 PM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

this may not be the best method.....
Try to store the datakey in a hidden template column having a label inside. Store the datakey in the label. inside the loop find the value of the lable just as u found the ckecbox....

Regards
Ganesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
checkbox trouble brainchild VB How-To 1 October 28th, 2007 09:34 PM
Asp.Net Checkbox in Datagrid. vivek_inos C# 2 December 5th, 2005 02:40 PM
Chapter 1 ASP.NET Trouble Shooting rragoonanan BOOK: Beginning ASP.NET 1.0 14 December 3rd, 2003 09:53 AM





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