C# .NET - Error - Asked By Jahir on 21-Jun-12 04:08 AM

this is my state table:
create table tbl_state(id bigint primary key identity,state nvarchar(max))
this is my city table:
create table tbl_city(id bigint primary key identity,state bigint,city nvarchar(max))
 
if i selected dropdownlist1 means it want to come that state here... but this my qry is displaying only id but i want to display city name how ?
adap = new SqlDataAdapter("select *from tbl_city where state='" + DropDownList1.SelectedItem.Value + "'", con);
 
this is my bindgrid qry:
 
  adap = new SqlDataAdapter("select b.state,c.city,a.hotelname,a.hotelimage from tbl_hotel a,tbl_state b,tbl_city c where a.state=b.id and a.city=c.id", con);     
TSN ... replied to Jahir on 21-Jun-12 04:27 AM

hi..

 

while binding the dropdown list just mention as shown below.

you need to specify dataTextFileds and Datavalue Fileds

 

ddlCity.DataSource = //DataFrom the Database which is stored in the Dataset

ddlCity.DataTextField = "City";
ddlCity.DataValueField = "
identityValue"
;
ddlCity.DataBind();

Jahir replied to TSN ... on 21-Jun-12 04:36 AM
thank you...
 then what is page indexchanging use ?
how to write code for that ?
TSN ... replied to Jahir on 21-Jun-12 05:20 AM

hi..

in order to handle when ever a page is changed , this event would help you..

<asp:gridview id="CustomersGridView"

allowpaging="true"

autogenerateeditbutton="true"

onpageindexchanging="CustomersGridView_PageIndexChanging"

runat="server">

protected void CustomersGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)

{

GridView1.PageIndex = e.NewPageIndex;

//Bind grid here

}