getting at data in gridview cells

M

Mike P

I am trying to get access to the data in different rows of my gridview
on a button click, in a similar way to the one I used with my 1.1
datagrids. But the cells always seem to be empty. Here is my code :

protected void btnSubmit_Click(object sender, EventArgs e)
{
//get list of pkcustomerrecords and email addresses, put into
generic list
List<EmailDetails> em = new List<EmailDetails>();

int intPKCustomerRecord;
string strConsultant;
string strEmailAddress;

for (int i = 0; i < GridView1.Rows.Count; i++)
{
if
(((CheckBox)GridView1.Rows.FindControl("chkSendEmail")).Checked ==
true)
{
intPKCustomerRecord =
Convert.ToInt32(GridView1.Rows.Cells[3].Text);
strConsultant =
Convert.ToString(GridView1.Rows.Cells[2].Text);
strEmailAddress =
Convert.ToString(GridView1.Rows.Cells[1].Text);

EmailDetails ed = new EmailDetails();
ed.PKCustomerRecord = intPKCustomerRecord;
ed.Consultant = strConsultant;
ed.EmailAddress = strEmailAddress;

em.Add(ed);
}
}

Can anybody help me out?
 
I

Ignacio Machin ( .NET/ C# MVP )

I am trying to get access to the data in different rows of my gridview
on a button click, in a similar way to the one I used with my 1.1
datagrids.  But the cells always seem to be empty.  Here is my code :

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        //get list of pkcustomerrecords and email addresses, put into
generic list
        List<EmailDetails> em = new List<EmailDetails>();

        int intPKCustomerRecord;
        string strConsultant;
        string strEmailAddress;

        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            if
(((CheckBox)GridView1.Rows.FindControl("chkSendEmail")).Checked ==
true)
            {
                intPKCustomerRecord =
Convert.ToInt32(GridView1.Rows.Cells[3].Text);
                strConsultant =
Convert.ToString(GridView1.Rows.Cells[2].Text);
                strEmailAddress =
Convert.ToString(GridView1.Rows.Cells[1].Text);

                EmailDetails ed = new EmailDetails();
                ed.PKCustomerRecord = intPKCustomerRecord;
                ed.Consultant = strConsultant;
                ed.EmailAddress = strEmailAddress;

                em.Add(ed);
            }
        }

Can anybody help me out?

*** Sent via Developersdexhttp://www.developersdex.com***


Have you seen what contact the Row has?
And why you want to do this?
Dont you have to datasource that you originally used?
 
I

Ignacio Machin ( .NET/ C# MVP )

I am trying to get access to the data in different rows of my gridview
on a button click, in a similar way to the one I used with my 1.1
datagrids.  But the cells always seem to be empty.  Here is my code :

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        //get list of pkcustomerrecords and email addresses, put into
generic list
        List<EmailDetails> em = new List<EmailDetails>();

        int intPKCustomerRecord;
        string strConsultant;
        string strEmailAddress;

        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            if
(((CheckBox)GridView1.Rows.FindControl("chkSendEmail")).Checked ==
true)
            {
                intPKCustomerRecord =
Convert.ToInt32(GridView1.Rows.Cells[3].Text);
                strConsultant =
Convert.ToString(GridView1.Rows.Cells[2].Text);
                strEmailAddress =
Convert.ToString(GridView1.Rows.Cells[1].Text);

                EmailDetails ed = new EmailDetails();
                ed.PKCustomerRecord = intPKCustomerRecord;
                ed.Consultant = strConsultant;
                ed.EmailAddress = strEmailAddress;

                em.Add(ed);
            }
        }

Can anybody help me out?

*** Sent via Developersdexhttp://www.developersdex.com***


Also , consider posting these kind of errors that are relevant
exclusively to ASP.NET to the aspnet NG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top