how to control a gridview by a button click outside the grid

Posted by Shoumik025 under ASP.NET on 5/8/2013 | Points: 10 | Views : 12213 | Status : [Member] | Replies : 4
how to control a gridview by a button click outside the grid..........
is it possible??




Responses

Posted by: Valley on: 5/8/2013 [Member] Starter | Points: 25

Up
0
Down
Yes.

Shoumik025, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sumank on: 5/9/2013 [Member] Starter | Points: 25

Up
0
Down
Yes, you can control gridview on button click.
For Example, you want to show data in gridview on button click,
so on button click event bind the gridview with data.
Suppose, you want to hide the gridview on click of another button then
set visible=false for that gridview.

On the button click page is posted to the server and we can make
changes to the gridview.

Regards
SumanK

Shoumik025, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Valley on: 5/9/2013 [Member] Starter | Points: 25

Up
0
Down
<asp:BoundField DataField="Notes" HeaderText="Notes" Visible="False" 

SortExpression="Notes" />
<asp:BoundField DataField="Notes" HeaderText="Notes" Visible="False"
SortExpression="Notes" />
<asp:ButtonField ButtonType="Image" ImageUrl="~/Images/Imgs.jpg"
Text="Button" />
-----------------------------------------------------------------------------------------------------

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridView1.Columns[2].Visible = true;
GridView1.Columns[3].Visible = true;
}


Shoumik025, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 5/9/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
If you want to show data from database into gridview with button click


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Gridview._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView id="g1" Runat="Server" AutoGenerateColumns="true">
</asp:GridView>

</div>
</form>
</body>
</html>


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;
namespace Gridview
{
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
string str;

protected void Page_Load(object sender, EventArgs e)
{
bindgrid();
}
private void bindgrid()
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "select * from students";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "students");
g1.DataMember = "students";
g1.DataSource = ds;
g1.DataBind();
con.Close();
}

}
}


If this post helps you mark it as answer
Thanks

Shoumik025, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response