Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 18, 2012 09:42 AM by Ravi Kumar Kurasala
Member
6 Points
39 Posts
May 17, 2012 10:41 AM|LINK
Hi,
This is the code am running in aspx page.
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { int i = Convert.ToInt32(((DataRowView)DropDownList1.SelectedValue).Row["CustomerID_i"].ToString()); //error while running this line SqlDataAdapter adp = new SqlDataAdapter("select * from Unit_Detail where UnitCustomerID_i = " + i, con); DataSet dt = new DataSet(); adp.Fill(dt, "Customer"); GridView1.DataSource = dt.Tables["Customer"]; //GridView1.DataBind(); }
why i am getting the Error : Cannot convert type 'string' to 'System.Data.DataRowView' .How cai solve it
All-Star
134527 Points
21579 Posts
Moderator
MVP
May 17, 2012 10:44 AM|LINK
keerthana4hari why i am getting the Error : Cannot convert type 'string' to 'System.Data.DataRowView'
keerthana4hari (DataRowView)DropDownList1.SelectedValue
the selectedvalue of the dropdownlist is an string - maybe int...
I think that the code should be
int i = Convert.ToInt32(DropDownList1.SelectedValue)
May 17, 2012 11:01 AM|LINK
I changed as per your suggestion i am getting not error but after selecting any option in dropdownlist not showing the table values in gridview. what can i do..to work it..
I changed as per your suggestion i am getting not error but after selecting any option in dropdownlist not showing the table values in gridview.
what can i do..to work it..
727 Points
155 Posts
May 17, 2012 11:08 AM|LINK
Firstly uncomment the line
GridView1.DataBind(); //the databind() method is required
and change the query to
SqlDataAdapter adp = new SqlDataAdapter("select * from Unit_Detail where UnitCustomerID_i = '" + i.ToString() + "'", con);
If it still does not work,change
int i=Convert.ToInt32(DropDownList1.SelectedItem.Value);
Participant
1594 Points
376 Posts
May 17, 2012 11:12 AM|LINK
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { SqlDataAdapter adp = new SqlDataAdapter("select * from Unit_Detail where UnitCustomerID_i = " +DropDownList1.SelectedValue., con); DataSet dt = new DataSet(); adp.Fill(dt, "Customer"); GridView1.DataSource = dt.Tables["Customer"]; //GridView1.DataBind(); }
Try it.
May 17, 2012 11:25 AM|LINK
it doesnt show any error..but its not working...if i select the option in dropdownlist the values in the gridview doesnt change...as per the selection..what could be the mistake?
May 17, 2012 11:26 AM|LINK
Did you uncomment the GridView1.DataBind();
That line is required. If it still does not work , it means your query returns nothing
May 17, 2012 11:27 AM|LINK
//GridView1.DataBind();
REmove above comment line; It should work. as
GridView1.DataBind();
May 17, 2012 11:37 AM|LINK
i uncomment before compiling my code...it doesnot work
kept break point near protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e).
The flow is not going till that.I have made fetching the database values to dropdownlist on page load.
The grid view control showing values of unit table up on page load.
NOw am trying to select the dropdownlist value so that i can view specific unit details in gridview.This is what am trying to do.
May 17, 2012 11:45 AM|LINK
Show your pageload code. paste it here
Populate the dropdownlist and gridview in pageload inside
if(!IsPostBack)
{ }
keerthana4ha...
Member
6 Points
39 Posts
Conversion Error...why?
May 17, 2012 10:41 AM|LINK
Hi,
This is the code am running in aspx page.
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
int i = Convert.ToInt32(((DataRowView)DropDownList1.SelectedValue).Row["CustomerID_i"].ToString()); //error while running this line
SqlDataAdapter adp = new SqlDataAdapter("select * from Unit_Detail where UnitCustomerID_i = " + i, con);
DataSet dt = new DataSet();
adp.Fill(dt, "Customer");
GridView1.DataSource = dt.Tables["Customer"];
//GridView1.DataBind();
}
why i am getting the Error : Cannot convert type 'string' to 'System.Data.DataRowView' .How cai solve it
ignatandrei
All-Star
134527 Points
21579 Posts
Moderator
MVP
Re: Conversion Error...why?
May 17, 2012 10:44 AM|LINK
the selectedvalue of the dropdownlist is an string - maybe int...
I think that the code should be
int i = Convert.ToInt32(DropDownList1.SelectedValue)
keerthana4ha...
Member
6 Points
39 Posts
Re: Conversion Error...why?
May 17, 2012 11:01 AM|LINK
Ravi Kumar K...
Member
727 Points
155 Posts
Re: Conversion Error...why?
May 17, 2012 11:08 AM|LINK
Firstly uncomment the line
GridView1.DataBind(); //the databind() method is required
and change the query to
SqlDataAdapter adp = new SqlDataAdapter("select * from Unit_Detail where UnitCustomerID_i = '" + i.ToString() + "'", con);
If it still does not work,change
int i=Convert.ToInt32(DropDownList1.SelectedItem.Value);
mishra.bhupe...
Participant
1594 Points
376 Posts
Re: Conversion Error...why?
May 17, 2012 11:12 AM|LINK
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { SqlDataAdapter adp = new SqlDataAdapter("select * from Unit_Detail where UnitCustomerID_i = " +DropDownList1.SelectedValue., con); DataSet dt = new DataSet(); adp.Fill(dt, "Customer"); GridView1.DataSource = dt.Tables["Customer"]; //GridView1.DataBind(); }Try it.
keerthana4ha...
Member
6 Points
39 Posts
Re: Conversion Error...why?
May 17, 2012 11:25 AM|LINK
it doesnt show any error..but its not working...if i select the option in dropdownlist the values in the gridview doesnt change...as per the selection..what could be the mistake?
Ravi Kumar K...
Member
727 Points
155 Posts
Re: Conversion Error...why?
May 17, 2012 11:26 AM|LINK
Did you uncomment the GridView1.DataBind();
That line is required. If it still does not work , it means your query returns nothing
mishra.bhupe...
Participant
1594 Points
376 Posts
Re: Conversion Error...why?
May 17, 2012 11:27 AM|LINK
REmove above comment line; It should work. as
keerthana4ha...
Member
6 Points
39 Posts
Re: Conversion Error...why?
May 17, 2012 11:37 AM|LINK
i uncomment before compiling my code...it doesnot work
kept break point near protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e).
The flow is not going till that.I have made fetching the database values to dropdownlist on page load.
The grid view control showing values of unit table up on page load.
NOw am trying to select the dropdownlist value so that i can view specific unit details in gridview.This is what am trying to do.
Ravi Kumar K...
Member
727 Points
155 Posts
Re: Conversion Error...why?
May 17, 2012 11:45 AM|LINK
Show your pageload code. paste it here
Populate the dropdownlist and gridview in pageload inside
if(!IsPostBack)
{
}