如何从gridview中选择一个值,然后使网格视图不可见 [英] How to select a value from gridview and then make the grid view invisible

查看:61
本文介绍了如何从gridview中选择一个值,然后使网格视图不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iam使用c#代码。我有2个文本框和一个按钮,我的数据库名称中有一个表作为customerMaster。我的查询是:

当点击按钮时会显示gridview,从中我可以选择customername和customer id,在选择值后,gridview应该不可见,并且应该看到sselected值文本框。

到目前为止我能做的是:

使gridview不可见,并且只有两个值可以从custompaable获得。客户名和身份证。

谁能告诉我我怎么做其余的事情?



急需!!



我尝试了什么:



iam using c# code for this. i have 2textbox and one button and a table in my database name as customerMaster. my query is:
when button is clicked the gridview is shown and from that i can select customername and customer id , after the value is selected the gridview shoud not be visible and the sselected values should be seen in textboxes.
till now im able to do is:
made the gridview invisible and only two values are available from the customertable . customername and id.
can anyone tell me how i do the rest?

its urgent need!!

What I have tried:

public partial class gridv : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        GridView1.Visible = false;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Data source = MICKEY\\SQLEXPRESS; Initial Catalog = rr; Integrated Security = True; User Id = k; Password = mickey");
        SqlCommand cmd = new SqlCommand("select customername,customeridno from customerMaster ");
        SqlDataAdapter da = new SqlDataAdapter(cmd.CommandText, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
        GridView1.Visible = true;


    }
}

推荐答案

在gridview中放一个允许的按钮用户选择该行,以及何时读取行中的值并将其放入文本框中。



如何:响应GridView控件中的按钮事件 [ ^ ]
Put a button in the gridview that allows the user to select that row, and when they do read the values from the row and put them in your text boxes.

How to: Respond to Button Events in a GridView Control[^]


我自己生成了它。



i generated it all by myself.

protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
       {
           TextBox19.Text = GridView2.SelectedRow.Cells[1].Text;
           TextBox20.Text = GridView2.SelectedRow.Cells[2].Text;

       }

       protected void Button1_Click(object sender, EventArgs e)
       {
           SqlConnection con = new SqlConnection ("Data Source = MICKEY\\SQLEXPRESS; Initial catalog = rr; User Id = k; Password = mickey; integrated security = True");
           //BDataAccess.dataConnect objda = new BDataAccess.dataConnect();
          // SqlConnection con = new SqlConnection(objda);

           SqlCommand cmd = new SqlCommand("select customername , customeridno from customerMaster");
           SqlDataAdapter da = new SqlDataAdapter(cmd.CommandText, con);
           DataSet ds = new DataSet();
           da.Fill(ds);
           GridView2.DataSource = ds;
           GridView2.DataBind();

       }

   }


这篇关于如何从gridview中选择一个值,然后使网格视图不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆