如何在按钮点击时触发gridview

如何在按钮点击时触发gridview

本文介绍了如何在按钮点击时触发gridview selectedindex更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net中有程序,它在gridview中显示产品详细信息。如果我单击gridview上的选择按钮,行项将选择并添加到相应的文本框中。但是我有一个提交按钮。所以我想将选定的索引更改事件添加到该提交按钮。请帮助。



这是我在gridview选择的索引中的代码已更改:

  GridViewRow   row   =   GridView1  .SelectedRow; 
TextBox1 文本 = row .Cells [1] .Text;
TextBox2 文本 = row .Cells [2] .Text;
TextBox3 文本 = row .Cells [3] .Text;
TextBox4 文本 = row .Cells [4] .Text;







如何将其添加到提交按钮点击事件。



添加回答:

 使用系统; 
使用 System.Collections;
使用 System.Configuration;
使用 System.Data;
使用 System.Linq;
使用 System.Web;
使用 System.Web.Security;
使用 System.Web.UI;
使用 System.Web.UI.HtmlControls;
使用 System.Web.UI.WebControls;
使用 System.Web.UI.WebControls.WebParts;
使用 System.Xml.Linq;
使用 System.Data.SqlClient;
使用 System.IO;
使用 System.Collections.Generic;

public partial class Default4:System.Web.UI.Page
{
SqlConnection con = new SqlConnection( 数据源= VISHNUIT;初始目录= sims1;集成安全性=真);
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
DataTable dt = new DataTable();
受保护 void Page_Load( object sender,EventArgs e)
{
Body.Attributes [ bgcolor ] = apple green;
}
protected void GridView1_SelectedIndexChanged( object sender,EventArgs e)
{
GridViewRow row = GridView1.SelectedRow;
TextBox3.Text = row.Cells [ 1 ]。文字;
TextBox4.Text = row.Cells [ 2 ]。文字;
TextBox5.Text = row.Cells [ 3 ]。文字;
}
受保护 void TextBox3_TextChanged( object sender,EventArgs e)
{
String str = select * from login where(uname like + @search +'%');
SqlCommand xp = new SqlCommand(str,con);
xp.Parameters.Add( @ search,SqlDbType.VarChar).Value = TextBox3.Text;
con.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = xp;
DataSet ds = new DataSet();
da.Fill(ds, uname);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
受保护 void Button1_Click(对象发​​件人,EventArgs e)
{

}
}





这里button1是我的提交按钮。

解决方案



I have program in asp.net which displays product details in gridview. If I click on the select button on the gridview that row items will select and added to the corresponding textboxes. But n0w I have a submit button. So I want to add the selected index changed event to that submit button. pls help.

this is my code in gridview selected index changed:

GridViewRow row = GridView1.SelectedRow;
        TextBox1.Text = row.Cells[1].Text;
        TextBox2.Text = row.Cells[2].Text;
        TextBox3.Text = row.Cells[3].Text;
        TextBox4.Text = row.Cells[4].Text;




how can I add this to the submit button click event.

Added from answering:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;
using System.Collections.Generic;

public partial class Default4 : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Data source = VISHNUIT;Initial Catalog = sims1; Integrated security= True");
    SqlCommand cmd = new SqlCommand();
    SqlDataReader dr;
    DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
    {
        Body.Attributes["bgcolor"] = "apple green";
    }
   protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridViewRow row = GridView1.SelectedRow;
        TextBox3.Text = row.Cells[1].Text;
        TextBox4.Text = row.Cells[2].Text;
        TextBox5.Text = row.Cells[3].Text;
    }
    protected void TextBox3_TextChanged(object sender, EventArgs e)
    {
        String str = "select * from login where (uname like  + @search + '%' )";
        SqlCommand xp = new SqlCommand(str,con);
        xp.Parameters.Add("@search", SqlDbType.VarChar).Value = TextBox3.Text;
        con.Open();
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = xp;
        DataSet ds = new DataSet();
        da.Fill(ds, "uname");
        GridView1.DataSource = ds;
        GridView1.DataBind();
        con.Close();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

    }
}



Here button1 is my submit button.

解决方案



这篇关于如何在按钮点击时触发gridview selectedindex更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 23:53