How does that work? Any good tutorials or tips? I greatly appreciate it.
Main Topics
Browse All TopicsI have this simple program that will get data out of the database and populate a Gridview. Each row has a checkbox and data from the database. Now when you check of the check box and click the submit button it is suppose to tell me the rows in which the checkbox of that row is checked but it always return all of them. Why is it doing that? I am thinking it might be a postback issue? Here is the code to the CS and ASPX page.
CS
------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.
using System.Web.UI.HtmlControls
using System.Data.SqlClient;
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//GridView1
//Application["pictureFile
temp();
}
protected void temp()
{
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionStr
SqlCommand myCommand = new SqlCommand("select bathid, model, size, sink, fixture, pic_sm from tblbathroom", myConnection);
myCommand.Connection.Open(
SqlDataAdapter da = new SqlDataAdapter(myCommand.C
DataSet ds = new DataSet();
da.Fill(ds);
//close connection
myConnection.Close();
da.Dispose();
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
CheckBox chkBox = null;
for (int i = 0; i < this.GridView1.Rows.Count;
{
chkBox = (CheckBox)this.GridView1.R
if (chkBox.Checked)
TextBox1.Text = TextBox1.Text + i;
}
}
}
ASPX
--------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtm
<html xmlns="http://www.w3.org/1
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" >
<Columns>
<asp:TemplateField HeaderText="select">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat = "server" />
</ItemTemplate></asp:Templ
</Columns>
</asp:GridView>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextB
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
</form>
</body>
</html>
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: chinu1310Posted on 2007-07-10 at 14:08:16ID: 19457791
Hi,
You can do it with the itemcommand of the gridview. Check if that works.