0

すべての企業にコンテンツをメールで送信する編集可能な GridView があります。Gridview の最初の行には、会社名が含まれています (1 行に 1 つの名前のみ)。最初の行の会社名に基づいて、特定の電子メール アドレスに Gridview を電子メールで送信したいと考えています。例 - 最初の行が companyname1 と等しい場合、電子メールを会社 1 に送信します。最初の行が会社 2 に等しい場合、メールを会社 2 に送信します。私は次のことを試みました:

//C# - ボタンの背後にあるコード スニペット

foreach (GridView item in gvCompanies.Rows)
        {
            if (item.SelectedRow.Cells[1].Text == "company1")
            {
                txtEmailAddresses.Text = "company1@gmail.com";
            }
            else if (item.SelectedRow.Cells[1].Text == "company2")
            {
                txtEmailAddresses.Text = "company2.com";
            }

            else if (item.SelectedRow.Cells[1].Text == "company3")
            {
                txtEmailAddresses.Text = "company3@aol.com";
            }

            else if (item.SelectedRow.Cells[1].Text == "company4")
            {
                txtEmailAddresses.Text = "company@aol.com";
            }
        }

...ここで何が間違っているかについて、誰かがガイダンスを提供できますか?

4

1 に答える 1

0

このようなことを試してみてください...

protected void gvCompanies_SelectedIndexChanged(object sender, EventArgs e)
{
 //for (int i = 0; i < gvCompanies.Rows.Count; i++)
 //       {
            if (gvCompanies.SelectedIndex == i)
            {
                String compName = gvCompanies.Rows[i].Cells[1].Text; //Gets the data cell value from the grid to string
                if(compName == "company1")
                {
                txtEmailAddresses.Text = "company1@gmail.com";
                }
                else if(compName == "company2")
                {
                txtEmailAddresses.Text = "company2@gmail.com";
                }
                ........and so on
            }
      // }
}

gridview の次の 2 つのプロパティを設定する必要があります。

1]AutoGenerateSelectButton="true"および
2] onselectedindexchanged="GridView1_SelectedIndexChanged"

于 2012-10-22T17:55:37.550 に答える