BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px"
CellPadding="3" CellSpacing="1" GridLines="None"
DataSourceID="SqlDataSource1">
protected void Page_Load(object sender, EventArgs e)
{
gridBind();
}
public void gridBind()
{
try
{
//open the db connection if it is closed...
if (connection.State == ConnectionState.Closed)
connection.Open();
string ColumnName = ddlColumn.SelectedValue;
string Value = txtColValue.Text;
command = new SqlCommand();
command.CommandText = "sp_Get_CustInfoInRecPay";
command.CommandType = CommandType.StoredProcedure;
command.Connection = connection;
command.Parameters.AddWithValue("@ColumnName", ColumnName);
command.Parameters.AddWithValue("@Value", Value);
SqlDataAdapter da = new SqlDataAdapter(command);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count == 0)
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
gridCustInfo.DataSource = ds;
gridCustInfo.DataBind();
int columncount = gridCustInfo.Rows[0].Cells.Count;
gridCustInfo.Rows[0].Cells.Clear();
gridCustInfo.Rows[0].Cells.Add(new TableCell());
gridCustInfo.Rows[0].Cells[0].ColumnSpan = columncount;
gridCustInfo.Rows[0].Cells[0].Text = "No Records Found";
}
else
{
gridCustInfo.DataSource = ds.Tables[0];
gridCustInfo.DataBind();
}
connection.Close();
if (connection.State == ConnectionState.Closed)
connection.Open();
string uid = ds.Tables[0].Rows[0]["UserId"].ToString();
command = new SqlCommand();
command.CommandText = "sp_Get_CustAccountfoInRecPay";
command.CommandType = CommandType.StoredProcedure;
command.Connection = connection;
command.Parameters.AddWithValue("@Value", uid);
SqlDataAdapter daAcc = new SqlDataAdapter(command);
DataSet dsAcc = new DataSet();
daAcc.Fill(dsAcc);
if (dsAcc.Tables[0].Rows.Count == 0)
{
dsAcc.Tables[0].Rows.Add(dsAcc.Tables[0].NewRow());
gridAccInfo.DataSource = dsAcc;
gridAccInfo.DataBind();
int columncount = gridAccInfo.Rows[0].Cells.Count;
gridAccInfo.Rows[0].Cells.Clear();
gridAccInfo.Rows[0].Cells.Add(new TableCell());
gridAccInfo.Rows[0].Cells[0].ColumnSpan = columncount;
gridAccInfo.Rows[0].Cells[0].Text = "No Records Found";
}
else
{
gridAccInfo.DataSource = dsAcc.Tables[0];
gridAccInfo.DataBind();
}
connection.Close();
if (connection.State == ConnectionState.Closed)
connection.Open();
command = new SqlCommand();
command.CommandText = "sp_Get_ControlValues";
command.CommandType = CommandType.StoredProcedure;
command.Connection = connection;
command.Parameters.AddWithValue("@uid", uid);
SqlDataAdapter daPack = new SqlDataAdapter(command);
DataSet dsPack = new DataSet();
daPack.Fill(dsPack);
ddlPackPeriod.SelectedIndex = ddlPackPeriod.Items.IndexOf(ddlPackPeriod.Items.FindByText(dsPack.Tables[0].Rows[0]["PackagePeriod"].ToString()));
//open the db connection if it is closed...
if (connection.State == ConnectionState.Closed)
connection.Open();
string packagePeriod = ddlPackPeriod.SelectedValue;
command = new SqlCommand();
command.CommandText = "sp_Get_PackName";
command.CommandType = CommandType.StoredProcedure;
command.Connection = connection;
command.Parameters.AddWithValue("@packagePeriod", packagePeriod);
ddlPackName.DataSource = command.ExecuteReader();
ddlPackName.DataValueField = "PackageId";
ddlPackName.DataTextField = "PackageName";
ddlPackName.DataBind();
ddlPackName.SelectedIndex = ddlPackPeriod.Items.IndexOf(ddlPackName.Items.FindByText(dsPack.Tables[0].Rows[0]["PackageName"].ToString()));
}
catch (Exception ex)
{
lblMessage.Text = "Please Enter Exact A/c No OR User Name for Data";
lblMessage.Visible = true;
}
finally //Close db Connection if it is open....
{
if (connection.State == ConnectionState.Open)
connection.Close();
}
}
I want to show empty grid when no action and whn I pass value from textbox and click on button then will bind data,(so its working)
and I have another button below my form page i.e, 'submit' when I click on this form fields inserting to my database but gridview not showing .and aftre passing the value from textbox and click on 'search' button thn gridview not showing..
so how to show grid forever?
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Hussain AhmedPosted Feb 26, 2015, 7:06 AM
Khargesh RajputPosted Feb 26, 2015, 6:54 AM
if(!page.ispostback)
{
gridBind();
}
and also write gridbind function on search button click