Solved

get the specific checkbox value when the button is clicked on gridview

Posted on 2012-03-19
2
396 Views
Last Modified: 2012-08-14
Hi EE,
I have GridView which has 3 checkboxes column and one button column. some records have all checkboxes are checked, some are just one or two are checked according to the database's check record.
suppose if i just check on the one checkbox and hit the button from the first record then it gets other checkboxes value too on my following code.

How can I get only the same record's selected checkbox value which is hitted.

[.aspx]
<asp:CheckBox ID="CheckBox0" runat="server" title="All" Checked='<%# HasRecord(Convert.ToInt32(Eval("art_id")),0) %>' />
<asp:CheckBox ID="CheckBox1" runat="server" title="All" Checked='<%# HasRecord(Convert.ToInt32(Eval("art_id")),1) %>' />
.
.
<asp:CheckBox ID="CheckBox5" runat="server" title="All" Checked='<%# HasRecord(Convert.ToInt32(Eval("art_id")),5) %>' />

<asp:Button ID="Button1" runat="server" Text="View" CommandName="view" CommandArgument='<%# Eval("art_id")%>'

[.aspx.cs]
   protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "view") {
 foreach (GridViewRow row in GridView1.Rows)
                {
                    artid = e.CommandArgument.ToString();
                    CheckBox cb0 = (CheckBox)row.FindControl("checkBox0");
                    CheckBox cb1 = (CheckBox)row.FindControl("checkBox1");
                    CheckBox cb2 = (CheckBox)row.FindControl("checkBox2");
                    CheckBox cb3 = (CheckBox)row.FindControl("checkBox3");
                    CheckBox cb4 = (CheckBox)row.FindControl("checkBox4");
                    CheckBox cb5 = (CheckBox)row.FindControl("checkBox5");  
                 if (cb0.Checked)
                    {
                        displayID = "0";
                    }
                    if (cb1.Checked)
                    {
                        displayID = "1";
                    }              
..........
            }
}
0
Comment
Question by:saloj
2 Comments
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37737186
0
 
LVL 16

Accepted Solution

by:
Swapnil Piparia earned 500 total points
ID: 37738255
Hi Saloj,

Please find below modified code which gives you specific checkbox value on which row you have clicked.
 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "view")
        {
            int index = Convert.ToInt32(e.CommandArgument); 
            GridViewRow row = GridView1.Rows[index];
                     artid = e.CommandArgument.ToString();
                    CheckBox cb0 = (CheckBox)row.FindControl("checkBox0");
                    CheckBox cb1 = (CheckBox)row.FindControl("checkBox1");
                    CheckBox cb2 = (CheckBox)row.FindControl("checkBox2");
                    CheckBox cb3 = (CheckBox)row.FindControl("checkBox3");
                    CheckBox cb4 = (CheckBox)row.FindControl("checkBox4");
                    CheckBox cb5 = (CheckBox)row.FindControl("checkBox5");  
                 if (cb0.Checked)
                    {
                        displayID = "0";
                    }
                    if (cb1.Checked)
                    {
                        displayID = "1";
                    }              
..........
            }
}

Open in new window


Thanks,
Netswap.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question