By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,975 Members | 1,236 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,975 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.
--
Saravanan K V
"Dan11" wrote:
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

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.