Help with Datagrid class. Trying to remove it in the following case..

D

Dan11

here's C sharp code:

Start code...

private void searchBtn_Click(object sender, System.EventArgs e)
{

//For sqlCommand1 is a search by Wkst ID (employeeID on pubs) params
if (txtEmployeeID.Text.Length > 0)
{
sqlCommand1.Parameters["@txtEmployeeID"].Value =
txtEmployeeID.Text;
sqlConnectSMS.Open();
System.Data.SqlClient.SqlDataReader dreader;
dreader = sqlCommand1.ExecuteReader();

DataGrid1.DataSource = dreader;
DataGrid1.DataBind();

dreader.Close();
sqlConnectSMS.Close();
}
else
{
//resets the data source to blank
DataGrid1.DataSource = null;
DataGrid1.DataBind();
}

....

}

End code

Basically, my question is in reference to the case when the if fails
(if (txtEmployeeID.Text.Length > 0)) and it goes to the else. This
means that I want DataGrid1 totally removed. The above shows up as
'nothing' on the asp.net page, but leaves this blank space. The reason
I see this page is because I have 4 DataGrid's back to back. If the
first 3 DataGrid objects are all set to null (like I have above), and
the DataGrid4 is present, then DataGrid4 has rows to display. On my
asp.net page, I have this huge space where the 3 datagrid's are blank.
That's because on my design view, it shows like this:

ASP.PAGE
Textbox(s)
DataGrid1
DataGrid2
DataGrid3
DataGrid4

I'm wondering if there is a command for the DataGrid to entirely remove
it, so that the space is removed.

Ideally, if the above situation happened, I'd want the DataGrid4 table
to show up right near the top of my page.

Thanks for any comments.
-Dan
 
G

Guest

Hi,

you can try to set the Visible property of the datagrid to false, if the
datasource is null and you do not want to display the grid.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top