首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在一个按钮中调用多个会话

在一个按钮中调用多个会话
EN

Stack Overflow用户
提问于 2013-09-01 07:31:47
回答 1查看 33关注 0票数 1

我有一个gridview rowCommand,它将在触发时获取行的索引。然后,我需要检索索引的所有值,以便包含在按钮update语句的where爪中。我使用多个会话来尝试,但它不起作用。这是我的密码。

代码语言:javascript
复制
    protected void gvawards_RowCommand(object sender, GridViewCommandEventArgs e)
    {
                    btnsaveawards.Visible = true;
                    if (e.CommandName == "Name")
                    {
                        int index = Convert.ToInt32(e.CommandArgument);
                        dremployer2.SelectedItem.Text = gvawards.Rows[index].Cells[1].Text;
                        txtawardtitle.Text = gvawards.Rows[index].Cells[2].Text;
                        txtyearawarded.Text = gvawards.Rows[index].Cells[3].Text;
                        Session["Employer2"] = dremployer2.SelectedValue;
                        Session["Award"] = txtawardtitle.Text;
                        Session["YearAwarded"] = txtyearawarded.Text;

                    }
    }

    protected void btnsaveawards_Click(object sender, EventArgs e)
    {
        int employer2 = int.Parse(Session["Employer2"].ToString());
        string awardtitle = Session["Award"].ToString();
        int yearawarded = int.Parse(Session["YearAwarded"].ToString());
        btnsaveawards.Visible = false;
        con.Open();
        string update = "update tblAwardsData set EmployerID='" + dremployer2.SelectedValue + "',AwardTitle='" + txtawardtitle.Text + "',YearAwarded='" + txtyearawarded.Text + "' where  EmployerID='" + employer2 + "' and AwardTitle='" + awardtitle + "' and YearAwarded='" + yearawarded + "' and IDNumber='" + 11277718 + "'";
        SqlCommand scmupdate = new SqlCommand(update, con);
        scmupdate.ExecuteNonQuery();
        view(); //Rebind the gridview
        dremployer2.SelectedItem.Text = "Select employer";
        txtawardtitle.Text = "";
        txtyearawarded.Text = "".ToString(); ;
        con.Close();
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-01 08:37:33

我不知道什么不适合你,但这肯定行不通:

代码语言:javascript
复制
 dremployer2.SelectedItem.Text = gvawards.Rows[index].Cells[1].Text;

您只分配文本,选定的值仍然是旧的。你应该这样做:

代码语言:javascript
复制
dremployer2.SelectedIndex = dremployer2.Items.IndexOf(dremployer2.Items.FindByText(  gvawards.Rows[index].Cells[1].Text));

因此,当您在会话中保存正确的选定值时:

代码语言:javascript
复制
Session["Employer2"] = dremployer2.SelectedValue;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18556253

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档