TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Dawood Abbas
NA
264
98.4k
how to bind empty grid forever
Feb 26 2015 6:48 AM
<asp:GridView ID="gridCustomer" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px"
CellPadding="3" CellSpacing="1" GridLines="None"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField HeaderText="#" />
<asp:BoundField DataField="UserId" HeaderText="Account Number" />
<asp:TemplateField HeaderText="Name">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:HyperLink ID="hyperName" runat="server">[hyperName]</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserName" HeaderText="User Name" />
<asp:BoundField DataField="Status" HeaderText="Status" />
<asp:BoundField DataField="PackagePeriod" HeaderText="Package Period" />
<asp:BoundField DataField="PackageName" HeaderText="Package Name" />
<asp:BoundField DataField="ActivationDate" HeaderText="Activation Date" />
<asp:BoundField DataField="OldExpiryDate" HeaderText="Account Expiry" />
<asp:BoundField DataField="Balance" HeaderText="Balance" />
<asp:BoundField DataField="PyingAmount" HeaderText="Last Paid Amount" />
<asp:BoundField DataField="LastPaidDate" HeaderText="Last Paid Date" />
<asp:BoundField DataField="LastUpdateTime" HeaderText="Last Acc Updated Time" />
<asp:BoundField DataField="AreaName" HeaderText="Area" />
<asp:BoundField DataField="MobNo" HeaderText="Mobile #" />
<asp:BoundField DataField="EmpName" HeaderText="Attended User" />
<asp:BoundField DataField="Address" HeaderText="Address" />
<asp:BoundField DataField="CreatedDate" HeaderText="Created Date" />
</Columns>
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
<PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#DEDFDE" ForeColor="Black" />
<SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#594B9C" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#33276A" />
</asp:GridView>
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?
Reply
Answers (
2
)
definition of QuotePrefix Quotesuffix
Regarding Network buffer and datareader data fetch c#