Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2012-03-19
2
Medium Priority
?
418 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37737186
0
 
LVL 16

Accepted Solution

by:
Swapnil Piparia earned 2000 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

618 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