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);
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........