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?


Khargesh RajputRank #616 · 3.9K reputationPosted Feb 26, 2015, 1:54 AM EST
if(!page.ispostback)
{
gridBind();
}
and also write gridbind function on search button click
Hussain AhmedRank #1,271 · 1.4K reputationPosted Feb 26, 2015, 2:06 AM EST