public DataSet Button_Select1(string a, string b, string c, int temp)
{
if (temp == 1)
cmd3 = new SqlCommand("select trvlsname,Bus_Type,Bus_Timing,Bus_Fair,Rout_Id from Bus_Information1 where SBus_From='" + a + "' AND EBus_To='" + b + "' AND Bus_Date='" + c + "'", sn);
SqlDataAdapter da3 = new SqlDataAdapter(cmd3);
DataSet ds = new DataSet();
da3.Fill(ds);
public void FillGrid()
{
try
{
DataSet ds = new DataSet();
ds = Button_Select1( U can pass ur parameters in this );
if (ds.Tables[0].Rows.Count == 0)
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
Thirisangu
Member
26 Points
187 Posts
if dataset is null, how to prevent dataset to bind in grid view.
May 17, 2012 06:39 AM|LINK
page1:
<asp:GridView ID="Gv1" runat="server" AutoGenerateColumns="False"
onrowcreated="Gv1_RowCreated"
onselectedindexchanged="Gv1_SelectedIndexChanged"
style="z-index: 1; left: 247px; top: 947px; position: absolute; height: 183px; width: 785px; right: 83px;"
Width="785px" AutoGenerateSelectButton="True">
<Columns>
<asp:BoundField DataField="TRVLSNAME" HeaderText="Travels Name"/>
<asp:BoundField DataField="Bus_Type" HeaderText="Bus Type"/>
<asp:BoundField DataField="Bus_Timing" HeaderText="Departure Time"/>
<asp:BoundField DataField="Bus_Fair" HeaderText="Fare"/>
<asp:BoundField DataField="Rout_Id" HeaderText="Rout_Id"/>
</Columns>
</asp:GridView>
data access layer:
public DataSet Button_Select1(string a, string b, string c, int temp)
{
if (temp == 1)
cmd3 = new SqlCommand("select trvlsname,Bus_Type,Bus_Timing,Bus_Fair,Rout_Id from Bus_Information1 where SBus_From='" + a + "' AND EBus_To='" + b + "' AND Bus_Date='" + c + "'", sn);
SqlDataAdapter da3 = new SqlDataAdapter(cmd3);
DataSet ds = new DataSet();
da3.Fill(ds);
}
page1.aspx:
protected void Gv1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = Gv1.SelectedRow;
//Session["gid"]
int id= Convert.ToInt32(row.Cells[5].Text);
Session["gprice"] = row.Cells[4].Text;
//Response.Redirect("Seat_Selection.aspx?Rout_Id="+Session["gid"]);
Response.Redirect("Seat_Selection.aspx?Rout_Id=" + id);
}
Here.. if dataset is null means it should not bound in grid view.
beause in my page1, i check for bus services in given date. if bus services is not given date, currently it shows no value
in grid view. it is ok. after that we try ti give date in that bus service is available, then i try to click the link
button for selecting the bus service, that time it shows error here...
protected void Gv1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = Gv1.SelectedRow;
//Session["gid"]
int id= Convert.ToInt32(row.Cells[5].Text); // here it shows 'zero' instead of showing the Rout_Id
Input string was not in a correct format.
Session["gprice"] = row.Cells[4].Text;
//Response.Redirect("Seat_Selection.aspx?Rout_Id="+Session["gid"]);
Response.Redirect("Seat_Selection.aspx?Rout_Id=" + id);
}
Please i am in need........
kirupa.v
Contributor
2070 Points
531 Posts
Re: if dataset is null, how to prevent dataset to bind in grid view.
May 17, 2012 07:03 AM|LINK
Hi,
Try like this
public void FillGrid()
{
try
{
DataSet ds = new DataSet();
ds = Button_Select1( U can pass ur parameters in this );
if (ds.Tables[0].Rows.Count == 0)
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
Gv1.DataSource = ds;
Gv1.DataBind();
Gv1.Rows[0].Visible = false;
}
else
{
Gv1.DataSource = ds;
Gv1.DataBind();
Gv1.Visible = true;
}
}
catch (Exception ex)
{
throw ex;
}
}
And in ur
protected void Gv1_SelectedIndexChanged(object sender, EventArgs e)
{
Button_Select1( U can pass ur parameters in this ); // U can bind thst function...
}
Reply me for any issues..
Frank Jiang ...
All-Star
16006 Points
1728 Posts
Microsoft
Re: if dataset is null, how to prevent dataset to bind in grid view.
May 22, 2012 05:48 AM|LINK
row.Cells[5].Text might be containing alphabetic characters, debugging to see what does it contain?
Feedback to us
Develop and promote your apps in Windows Store