Solved

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

Posted on 2012-03-19
2
394 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now