-1

如何通过检查其他列中的项目模板(标签)值等于给定文本,使用放置在gridview中的图像按钮重定向到另一个页面。

this is my code:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataTable dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter("select ID,SurveyName from SurveyMaster1  union select -1,'Select'", con);
            da.Fill(dt);
            DropDownList1.DataSource = dt;
            DropDownList1.DataValueField = "ID";
            DropDownList1.DataTextField = "SurveyName";
            DropDownList1.DataBind();
            DropDownList1.SelectedValue = "-1";
        }
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter("SELECT Question,QuestionType FROM Questions  WHERE SurveyID = '"+ DropDownList1.SelectedValue.ToString() +"'" , con);
        da.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }


protected void imgbtnEdit_Click(object sender, ImageClickEventArgs e)
    {
 GridViewRow grdSelRow = GridView1.SelectedRow;

        TextBox textInt = (TextBox)GridView1.FindControl("text1");

        if (textInt.Text == "Text")
        {
            Response.Redirect("Text.aspx");
        }            
    }

任何人都请帮助我.. 可能是我的问题不太清楚。

4

3 回答 3

1
protected void imgbtnEdit_Click(object sender, ImageClickEventArgs e)
{
    ImageButton imgbtnEdit = (ImageButton)sender;
    GridViewRow gr = (GridViewRow)imgbtnEdit.NamingContainer;
    TextBox textInt = (TextBox)gr.FindControl("text1");
    if (textInt.Text == "Text")
    {
        Response.Redirect("Text.aspx");
    }
}

试试这个代码。

于 2013-08-23T05:42:21.610 回答
0

试试下面:(TextBox)GridViewRow.FindControl("text1");换行

 protected void imgbtnEdit_Click(object sender, ImageClickEventArgs e)
        {
     GridViewRow grdSelRow = GridView1.SelectedRow;

            TextBox textInt = (TextBox)GridViewRow.FindControl("text1");

            if (textInt.Text == "Text")
            {
                Response.Redirect("Text.aspx");
            }            
        }
于 2013-08-23T05:41:55.823 回答
0

在 gridview 的 RowCommand 事件中编写代码

给图像按钮 CommandName 属性 =“编辑”

 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("Edit"))
            {


        TextBox textInt = (TextBox)GridView1.Rows[e.RowIndex].FindControl("text1");

        if (textInt.Text == "Text")
        {
            Response.Redirect("Text.aspx");
        }   
        }
    }
于 2013-08-23T06:18:14.823 回答