开发者

Show and hide grid view selected rows particular cell

开发者 https://www.devze.com 2023-03-04 05:40 出处:网络
Currently I\'m working on one project. There are total 5 columns in grid in which 2 are visible false.

Currently I'm working on one project.

There are total 5 columns in grid in which 2 are visible false.

name     email_id_X         email_id                 mobile_no_X   mobile_no   SELECT
---------------开发者_如何转开发----------------------------------- ---------------------------------
Mahesh  maXXXXXXahoo.co.in  maheshsbhoye@yahoo.co.in 98XXXXXX96    986769696   SELECT
Kiran   kiXXXXXX.in         kiran@yahoo.co.in        93XXXXXX333   9333333333  SELECT 
Kiran   kiXXXXXX.in         kiran@yahoo.co.in        93XXXXXX333   9333333333  SELECT 
Kiran   kiXXXXXX.in         kiran@yahoo.co.in        93XXXXXX333   9333333333  SELECT 
Amit    AmXXXXXXin          Amit@yahoo.co.in         93XXXXXX333   9333333333  SELECT 

So please tell me how to hide the column email_id and mobile_no. and when user click on select that time he can only see the selected rows email_id and mobile_no.

Thanks.


First set visible=false for those two columns. Then to get only the row u have selected, change the datasourceid and bind the data in the gridview1_SelectedIndexchanged event.

First the query for datasource it would be like Select * from table1. When you are binding for the second time, when you have clicked the select, then you're query should be like Select * from table1 where emailid=xyz.


You can do this using the RowCommand event. like..

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Select")
    {
        GridView1.Columns[2].Visible = false;
        GridView1.Columns[4].Visible = false;
    }
}

Edit:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Select")
    {
        GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
        row.Cells[2].Visible = false;
        row.Cells[4].Visible = false;
    }
}


To hide certain columns you can have this in the code behind:

GridView1.Columns[2].Visible = false;
GridView1.Columns[3].Visible = false;

This will hide the 3rd and 4th columns of the GridView.

0

精彩评论

暂无评论...
验证码 换一张
取 消