User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 391,687 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,207 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 1049 | Replies: 5
Reply
Join Date: May 2008
Posts: 10
Reputation: Shubhib is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Shubhib Shubhib is offline Offline
Newbie Poster

problem regarding check box in gridview

  #1  
Jun 21st, 2008
sir, i'm using ASP.Net 2.0,
i'm using a gridview in a form and i want to create a check boxes dynamically in each row of my grid view so that i can select multiple values from that grid, i want to use those selected values for some manipulation in the same form.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Posts: 13
Reputation: raj416 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
raj416 raj416 is online now Online
Newbie Poster

Re: problem regarding check box in gridview

  #2  
Jun 21st, 2008
{
foreach (GridViewRow row in GridView1.Rows) {
if (((CheckBox)row.FindControl("CheckBox1")).Checked == true) {
((CheckBox)rows.FindControl("CheckBox1")).Text();
}
}
}
try this code ... hope it will work for you
Reply With Quote  
Join Date: May 2008
Posts: 10
Reputation: Shubhib is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Shubhib Shubhib is offline Offline
Newbie Poster

Re: problem regarding check box in gridview

  #3  
Jun 23rd, 2008
thanks for ur reply but this is not working, can u tell me where to put this code, and it is giving error when i write it there.
Last edited by Shubhib : Jun 23rd, 2008 at 1:02 am.
Reply With Quote  
Join Date: Apr 2007
Posts: 234
Reputation: greeny_1984 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 8
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz in Training

Re: problem regarding check box in gridview

  #4  
Jun 24th, 2008
u have to use row command event to achieve this functionality.
Reply With Quote  
Join Date: Dec 2006
Location: United States
Posts: 612
Reputation: binoj_daniel is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 14
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: problem regarding check box in gridview

  #5  
Jun 24th, 2008
First add this code on the .aspx file to add checkboxes to GridView

<asp:TemplateField HeaderText="Delete" ShowHeader="False">
<ItemTemplate>
<asp:CheckBox ID="chkDeleteRows" runat="server"/>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="lbDelete" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton>
</FooterTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>

Then locate

protected void gv_RowDeleting(object sender, GridViewDeleteEventArgs e) for your GridView and place the code below.

// Looping through all the rows in the GridView
foreach (GridViewRow row in gv.Rows)
{
CheckBox checkbox = (CheckBox)row.FindControl("chkDeleteRows");
//Check if the checkbox is checked.
if (checkbox.Checked)
{
// Pass the Row ID to the DeleteList function
DeleteList(Convert.ToInt32(gv.DataKeys[row.RowIndex].Values[0]));
// DataKeys should be defined in the GridView property on the aspx page along with the delete button handler like this (OnRowDeleting="gv_RowDeleting")
// DataKeyNames="ROWID" (this should be the Primary Key in the table.)
}
}
Reply With Quote  
Join Date: May 2008
Posts: 10
Reputation: Shubhib is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Shubhib Shubhib is offline Offline
Newbie Poster

Re: problem regarding check box in gridview

  #6  
Jun 26th, 2008
sir this thing is not working, basically i'm facing a prob because of Direct Cast and Find control. when i'm writing a cond for checking checkbox is checked or not then it is always coming false. i don't know how to use find control or direct cast for this condition. please help me. i'm in very much prob
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ASP.NET Marketplace
Thread Tools Display Modes

Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 2:27 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC