Rajar Ahmed
asked on
will QUERY BUILDER in SQLdatasource reads gridview cell value..??
Is it possible .. to get gridview cell value in the querybuilder of sqldatasource control.
My issue is . am using a gridview, in that there r three columns .
namely
id,name,quantity
where as for name field am using dropdown list,
My Criteria...
1.am populating name from db in dropdown list using sqldatasource ctrl . which is too ec . But wat really not happening is . i want to bind dropdown according to id field index value in gridviw.. in otherwords I want to populate by using the gridview cell of 0 value ...is it possible..to in query builder. . ??
For eg ...(this is just for understanding like this...).
select name from table where id= row.Cells(0).Text) ...??
.can v get index value of gridview in querybuilder in sqldatasource ctrl....????
if its not possible y...???Plz suggest ....
My issue is . am using a gridview, in that there r three columns .
namely
id,name,quantity
where as for name field am using dropdown list,
My Criteria...
1.am populating name from db in dropdown list using sqldatasource ctrl . which is too ec . But wat really not happening is . i want to bind dropdown according to id field index value in gridviw.. in otherwords I want to populate by using the gridview cell of 0 value ...is it possible..to in query builder. . ??
For eg ...(this is just for understanding like this...).
select name from table where id= row.Cells(0).Text) ...??
.can v get index value of gridview in querybuilder in sqldatasource ctrl....????
if its not possible y...???Plz suggest ....
ASKER
if i used this <%#DataBinder.Eval( Container.DataItem, "ID" )%>,am getting error , of syntax error of converting varchar to int ..kindly suggest
ASKER
well now trying ur program, i ll get to no wat is comin ....
Kindly help.....If der was ny erro ,
jst writing the code for according for my issue
private void PopulateDropDownListNameBy ID(string ID, DropDownList ddlname)
{
//query and populate ddlName
}
Thanks....lll let u no soon,......
Kindly help.....If der was ny erro ,
jst writing the code for according for my issue
private void PopulateDropDownListNameBy
{
//query and populate ddlName
}
Thanks....lll let u no soon,......
if i used this <%#DataBinder.Eval( Container.DataItem, "ID" )%>,am getting error , of syntax error of converting varchar to int ..kindly suggest
--> it means it gets the data out no problem, it's just casting, you might wanna try around with these cast and convert. Is that SQL error, or compiler error.
Try another method and tell me if you need further assistance
JINN
--> it means it gets the data out no problem, it's just casting, you might wanna try around with these cast and convert. Is that SQL error, or compiler error.
Try another method and tell me if you need further assistance
JINN
ASKER
select id,(select ame from table where id=othrtable.id)as resname from othrtable where id=<%#DataBinder.Eval( Container.DataItem, "ID" )%>
this i entered in querybuilder , which returned that error..
this i entered in querybuilder , which returned that error..
ASKER
the below u given for datagrid, if its gridview means , wthr i should use databound or databind Event . ??
protected void dgUserPasswords_ItemDataBound(object sender, DataGridItemEventArgs e)
{
// Check if the current row contains items; if it's a header or footer row that will throw an error
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//get the ID
string id = DataBinder.Eval(e.Item.DataItem, "ID").ToString();
//find the current dropdown list:
DropDownList ddlName = e.Item.FindControl("ddlName");
//NOW you have the current ID and the dropdownlist -> populate the dllName dropdownlist
PopulateDropDownListNameByID(id, ddlName);
}
}
private void PopulateDropDownListNameByID(string ID, DropDownList ddlname)
{
//query and populate ddlName
}
ASKER
I did the followin code,but cudn retrive ...
As i need resname in (dropdown list) value with fid index...
i ve three tables
1.foodtable field
fid int(identity(1,1),primary)
fname varchar
table 2:Restauranttable
1.Rid primary key
2. resname varchar
table3 : pricetable
1.pid int(identity(1,1),primary)
2.fid int foriegn key(foodtable)
3..rid int foreign key(resttable)
4.price float
My gridview
fid(maintable) resname(resttable) in dropdown
Plz helpme .. to retreive details in dropdown list ..
Thanks...
As i need resname in (dropdown list) value with fid index...
i ve three tables
1.foodtable field
fid int(identity(1,1),primary)
fname varchar
table 2:Restauranttable
1.Rid primary key
2. resname varchar
table3 : pricetable
1.pid int(identity(1,1),primary)
2.fid int foriegn key(foodtable)
3..rid int foreign key(resttable)
4.price float
My gridview
fid(maintable) resname(resttable) in dropdown
Plz helpme .. to retreive details in dropdown list ..
Thanks...
protected void GridView1_DataBound(object sender, EventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//get the ID
string id = DataBinder.Eval(e.Item.DataItem, "fid").ToString();
//find the current dropdown list:
DropDownList ddlName = e.Item.FindControl("DropdownList1");
//NOW you have the current ID and the dropdownlist -> populate the dllName dropdownlist
PopulateDropDownListNameByID(id, ddlName);
}
}
private void PopulateDropDownListNameByID(string ID, DropDownList ddlname)
{
//query and populate ddlName
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("Select fid,(select resname from restable where rid=maintable.rid)as resname from maintable", con);
da.Fill(ds);
return ds;
}
can you trace down whether it is SQL error or Compiler error ?? Which type the field ID is? varchar or int? Int I guess right?
Try:
<%# Int32.Parse(DataBinder.Eva l( Container.DataItem, "ID" )) %>
The GridView DataBound will be fired after all the row has been bounded to gridview from datasource. You can use this to change footer text (such as summary infor ...)
There are orders in which you can find the best moment to fulfill your wish, for your case, using RowDataBound is the best option.
Refer to this article to have more information
http://weblogs.asp.net/meligy/archive/2008/01/25/gridview-databinding-events.aspx
Hope this helps
JINN
Try:
<%# Int32.Parse(DataBinder.Eva
The GridView DataBound will be fired after all the row has been bounded to gridview from datasource. You can use this to change footer text (such as summary infor ...)
There are orders in which you can find the best moment to fulfill your wish, for your case, using RowDataBound is the best option.
Refer to this article to have more information
http://weblogs.asp.net/meligy/archive/2008/01/25/gridview-databinding-events.aspx
Hope this helps
JINN
What you did was returning a DataSet while the PopulateDropDownListNameBy ID is a method return void, this is a custom method as my suggestion you can do:
And you have to do this in RowDataBound (as each grid row is binded). Go to GridView property to set this event
You also have to configure the GridView properly in your aspx file. (with databoundField etc.)
Hope this helps
JINN
And you have to do this in RowDataBound (as each grid row is binded). Go to GridView property to set this event
You also have to configure the GridView properly in your aspx file. (with databoundField etc.)
Hope this helps
JINN
private void PopulateDropDownListNameByID(string ID, DropDownList ddlname)
{
//query and populate ddlName
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("Select fid,(select resname from restable where rid=maintable.rid)as resname from maintable", con);
da.Fill(ds);
ddlname.Items.Clear();
ddlname.DataSource = ds.Tables[0];
ddlname.DataValueField = "resname";
ddlname.DataTextField = "resname";
ddlname.DataBind();
}
ASKER
Can u able to understand my issue, if not ll tell again, okay ..below are the error i got when i used this code which u said b4,
Plz tell necesary changes to take ....Thanks lukin frwd for ur help////.......
Error 1 'System.Web.UI.WebControls
Error 2 'System.Web.UI.WebControls
Error 3 'System.Web.UI.WebControls
Error 4 'System.Web.UI.WebControls
Error 5 The name 'fid' does not exist in the current context
public partial class griduser : System.Web.UI.Page
{
//int fidnew;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//GridView1.DataSource = resnameddl1().Tables[0];
GridView1.DataBind();
}
}
//public DataSet resnameddl1()
//{
// string constr = ConfigurationManager.AppSettings["constring"];
// SqlConnection myconnection = new SqlConnection(constr);
// DataSet ds = new DataSet();
// string cmd = "select distinct fid,(select fname from foodtable where fid=maintable.fid) as fname,dbo.resname(fid) as resname from maintable";
// SqlDataAdapter da = new SqlDataAdapter(cmd, myconnection);
// da.Fill(ds, "maintable");
// return ds;
//}
//protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
//{
// DataTable mytable = new DataTable();
// DataColumn restid = new DataColumn("rid");
// DataColumn restname1 = new DataColumn("resname1");
// mytable.Columns.Add(restid);
// mytable.Columns.Add(restname1);
// DataSet ds = new DataSet();
// ds = resnameddl1();
// int fid = 0;
// string expression = string.Empty;
// string rnames;
// if (e.Row.RowType == DataControlRowType.DataRow)
// {
// fid = Int32.Parse(e.Row.Cells[0].Text);
// expression = "fid = " + fid;
// DropDownList ddl = (DropDownList)e.Row.FindControl("dropdownlist1");
// DataRow[] rows = ds.Tables[0].Select(expression);
// rnames = "";
// DataRow newrow = mytable.NewRow();
// foreach (DataRow row in rows)
// {
// //string temprest = "resname1";
// //string[] temprestarr = temprest.Split(',');
// fidnew = Convert.ToInt32(row["fid"]);
// rnames = rnames + row["resname"] + ",";
// }
// newrow["rid"] = Convert.ToInt32(fidnew);
// newrow["resname1"] = rnames;
// mytable.Rows.Add(newrow);
// ddl.DataSource = mytable;
// ddl.DataTextField = "resname1";
// ddl.DataValueField = "rid";
// ddl.DataBind();
// }
//}
//protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
//{
// DataSet ds = new DataSet();
// ds = resnameddl1();
// if (e.Row.RowType == DataControlRowType.DataRow)
// {
// DropDownList ddl = (DropDownList)e.Row.FindControl("dropdownlist1");
// ddl.DataSource = ds;
// ddl.DataTextField = "resname";
// ddl.DataValueField = "fid";
// ddl.DataBind();
// }
//}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//get the ID
string id = DataBinder.Eval(e.Item.DataItem, "fid").ToString();
//find the current dropdown list:
DropDownList ddlName = e.Item.FindControl("DropdownList1");
//NOW you have the current ID and the dropdownlist -> populate the dllName dropdownlist
PopulateDropDownListNameByID(fid, ddlName);
}
}
// protected void Button1_Click(object sender, EventArgs e)
//{
// Response.Redirect("maintable.aspx");
//}
private void PopulateDropDownListNameByID(string fid, DropDownList ddlname)
{
//query and populate ddlName
string constr = ConfigurationManager.AppSettings["constring"];
SqlConnection myconnection = new SqlConnection(constr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("Select fid,(select resname from restable where rid=maintable.rid)as resname from maintable", myconnection);
da.Fill(ds);
ddlname.Items.Clear();
ddlname.DataSource = ds.Tables[0];
ddlname.DataValueField = "resname";
ddlname.DataTextField = "resname";
ddlname.DataBind();
}
}
ASKER
i think , previous one ll be confusing below code is wat is required things u ve to luk...
WHich r things i changed as ur valuable sayings...........
WHich r things i changed as ur valuable sayings...........
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class griduser : System.Web.UI.Page
{
//int fidnew;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//GridView1.DataSource = resnameddl1().Tables[0];
GridView1.DataBind();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//get the ID
string id = DataBinder.Eval(e.Item.DataItem, "fid").ToString();
//find the current dropdown list:
DropDownList ddlName = e.Item.FindControl("DropdownList1");
//NOW you have the current ID and the dropdownlist -> populate the dllName dropdownlist
PopulateDropDownListNameByID(fid, ddlName);
}
}
private void PopulateDropDownListNameByID(string fid, DropDownList ddlname)
{
//query and populate ddlName
string constr = ConfigurationManager.AppSettings["constring"];
SqlConnection myconnection = new SqlConnection(constr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("Select fid,(select resname from restable where rid=maintable.rid)as resname from maintable", myconnection);
da.Fill(ds);
ddlname.Items.Clear();
ddlname.DataSource = ds.Tables[0];
ddlname.DataValueField = "resname";
ddlname.DataTextField = "resname";
ddlname.DataBind();
}
}
<div><asp:GridView ID="GridView1" runat="server" style="left: 157px; position: relative; top: 141px" OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="False" >
<Columns>
<asp:BoundField DataField="fid" HeaderText="fid" />
<asp:BoundField HeaderText="Fname" DataField="fname"/>
<asp:TemplateField HeaderText="rname">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" Style="position: relative">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="price" />
<asp:TemplateField HeaderText="Quantity">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Style="position: relative"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField CommandName="addcart" HeaderText="ADDCART" Text="Button" />
</Columns>
</asp:GridView>
Sorry my bad, I dont have my compiler running right now, here is the correction
Jinn
PS: I do understand your issues (we have had quite a lot of similar cases ^^)
Jinn
PS: I do understand your issues (we have had quite a lot of similar cases ^^)
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
//get the ID
string id = e.Row.Cells[0].Text;
//find the current dropdown list:
DropDownList ddlName = e.Row.FindControl("DropdownList1") As DropDownList;
//NOW you have the current ID and the dropdownlist -> populate the dllName dropdownlist
PopulateDropDownListNameByID(fid, ddlName);
}
}
private void PopulateDropDownListNameByID(string fid, DropDownList ddlname)
{
//query and populate ddlName
string constr = ConfigurationManager.AppSettings["constring"];
SqlConnection myconnection = new SqlConnection(constr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("Select fid,(select resname from restable where rid=maintable.rid)as resname from maintable", myconnection);
da.Fill(ds);
ddlname.Items.Clear();
ddlname.DataSource = ds.Tables[0];
ddlname.DataValueField = "fid";
ddlname.DataTextField = "resname";
ddlname.DataBind();
}
Gotcha, extremely about the confusion before, I was refering to DataGrid instead of GridView, >.< as we have a lot of different controls and I took one so you can have an idea, accidentally, I got the DataGrid instead >.<
The correction above should work
JINN
The correction above should work
JINN
ASKER
for this line---->>>PopulateDropDow nListNameB yID(fid, ddlName);
ERROR.....The name 'fid' does not exist in the current context
Thnkss hor helpin so far, .....i had changed many things so far,
Now code is totaly diff as i did b4.. plz enlightn mistake if there any .....
ERROR.....The name 'fid' does not exist in the current context
Thnkss hor helpin so far, .....i had changed many things so far,
Now code is totaly diff as i did b4.. plz enlightn mistake if there any .....
public partial class griduser : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
---------- DO I NEED ANY CODE HERE ---
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
//get the ID
string id = e.Row.Cells[0].Text;
//find the current dropdown list:
DropDownList ddlName = (DropDownList)e.Row.FindControl("dropdownlist1");
//NOW you have the current ID and the dropdownlist -> populate the dllName dropdownlist
PopulateDropDownListNameByID(fid, ddlName);<<<-----ERROR LINE
}
}
private void PopulateDropDownListNameByID(string fid, DropDownList ddlname)
{
//query and populate ddlName
string constr = ConfigurationManager.AppSettings["constring"];
SqlConnection myconnection = new SqlConnection(constr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("Select fid,(select resname from restable where rid=maintable.rid)as resname from maintable", myconnection);
da.Fill(ds);
ddlname.Items.Clear();
ddlname.DataSource = ds.Tables[0];
ddlname.DataValueField = "rid";
ddlname.DataTextField = "resname";
ddlname.DataBind();
}
}
Please do ,check wthr, my aspx is correct....!!!
<div><asp:GridView ID="GridView1" runat="server" style="left: 157px; position: relative; top: 141px" OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="False" >
<Columns>
<asp:BoundField DataField="fid" HeaderText="fid" />
<asp:BoundField HeaderText="Fname" DataField="fname"/>
<asp:TemplateField HeaderText="rname">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" Style="position: relative">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="price" />
<asp:TemplateField HeaderText="Quantity">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Style="position: relative"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField CommandName="addcart" HeaderText="ADDCART" Text="Button" />
</Columns>
ASKER
select id,(select name from table where id=othrtable.id)as resname from othrtable where id=<%#DataBinder.Eval( Container.DataItem, "ID" )%>
Plz format this code as u say .....how to change accordin for gridview. ...???i din get yaar srryy...
Wats THIS >.< ????????
Hi,
Line 15 should be fid instead of id, you can use the compiler to verify the syntax error.
if(e.Row.RowType == DataControlRowType.DataRow )
{
//get the ID
string fid = e.Row.Cells[0].Text;
In PageLoad: it depends on what do you want to do when the page is Load or postback. In page life circle this Page_Load method is fired before Button_Click, SelectedIndexChange, RowDataBouond are called.
So in another scenarios, for example: when you have dynamicontrols added, they will be done here otherwise their buttons will not be register.
The Page_Load will always be fired as the page is call. In your case, I haven't seen anything that you need to do there.
Try put:
this.Title = "Users page"; in page_Load and put a break point there, debug, you will see it will be fired before RowDataBound event is fired ^^
Hope this give you some idea
JINN
Line 15 should be fid instead of id, you can use the compiler to verify the syntax error.
if(e.Row.RowType == DataControlRowType.DataRow
{
//get the ID
string fid = e.Row.Cells[0].Text;
In PageLoad: it depends on what do you want to do when the page is Load or postback. In page life circle this Page_Load method is fired before Button_Click, SelectedIndexChange, RowDataBouond are called.
So in another scenarios, for example: when you have dynamicontrols added, they will be done here otherwise their buttons will not be register.
The Page_Load will always be fired as the page is call. In your case, I haven't seen anything that you need to do there.
Try put:
this.Title = "Users page"; in page_Load and put a break point there, debug, you will see it will be fired before RowDataBound event is fired ^^
Hope this give you some idea
JINN
ASKER
Now i see a empty page........ No Error But,,,,.CAnt able to c grid
Not able to c my grid ... WHere am i wrong...???
Plz tell...
Not able to c my grid ... WHere am i wrong...???
Plz tell...
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
//get the ID
string fid = e.Row.Cells[0].Text;
//find the current dropdown list:
DropDownList ddlName = (DropDownList)e.Row.FindControl("dropdownlist1");
//NOW you have the current ID and the dropdownlist -> populate the dllName dropdownlist
PopulateDropDownListNameByID(fid, ddlName);
}
}
private void PopulateDropDownListNameByID(string fid, DropDownList ddlname)
{
//query and populate ddlName
string constr = ConfigurationManager.AppSettings["constring"];
SqlConnection myconnection = new SqlConnection(constr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("Select fid,(select resname from restable where rid=maintable.rid)as resname from maintable", myconnection);
da.Fill(ds);
ddlname.Items.Clear();
ddlname.DataSource = ds.Tables[0];
ddlname.DataValueField = "rid";
ddlname.DataTextField = "resname";
ddlname.DataBind();
}
}
I am not so sure what error do you have with that line, you haven't tell me if the FID column in your database is Int or Varchar, and what error you got from (SQL or VS)
ok try this:
select id,(select name from table where id=othrtable.id)as resname from othrtable where id=<%# Convert.ToInt32(DataBinder .Eval( Container.DataItem, "ID")) %>
or if FID is varchar:
select id,(select name from table where id=othrtable.id)as resname from othrtable where id='<%# DataBinder.Eval( Container.DataItem, "ID").ToString() %>'
Test around with it
JINN
ok try this:
select id,(select name from table where id=othrtable.id)as resname from othrtable where id=<%# Convert.ToInt32(DataBinder
or if FID is varchar:
select id,(select name from table where id=othrtable.id)as resname from othrtable where id='<%# DataBinder.Eval( Container.DataItem, "ID").ToString() %>'
Test around with it
JINN
Ok, then it is good now. Your problem in the new page is you haven't bind the gridView in any datasource, bind it first (bind to objectDataSource or dynamically from a dataset somewhere). Look at my example, change your query accordingly
Make sure everytime you Open and Close the connection
JINN
Make sure everytime you Open and Close the connection
JINN
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//query and populate ddlName
string constr = ConfigurationManager.AppSettings["constring"];
SqlConnection myconnection = new SqlConnection(constr);
DataSet ds = new DataSet();
myconnection.Open()
SqlDataAdapter da = new SqlDataAdapter("Select * from Users", myconnection);
da.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
myconnection.Close();
}
}
ASKER
my error is in VS query buider of sqldatasource contrl...
Fid is int
So, i used
select id,(select name from table where id=othrtable.id)as resname from othrtable where id=<%# Convert.ToInt32(DataBinder .Eval( Container.DataItem, "ID")) %>
ERror is now
Ensure select command properties is valid(its A message box while clicking test query)
Line 1 : Incorrect syntax near '<'.
Fid is int
So, i used
select id,(select name from table where id=othrtable.id)as resname from othrtable where id=<%# Convert.ToInt32(DataBinder
ERror is now
Ensure select command properties is valid(its A message box while clicking test query)
Line 1 : Incorrect syntax near '<'.
ASKER
While using code, am gettin
o/p was like this in gridview
fid Resname(Dropdown LIST)
56 Restaurant A RestaurantB Restaurant
56 Restaurant A RestaurantB Restaurantc
56 Restaurant A RestaurantB Restaurantc
56 Restaurant A RestaurantB Restaurantc
63 Restaurant A RestaurantB Restaurantc
63 Restaurant A RestaurantB Restaurantc
63 Restaurant A RestaurantB Restaurantc
63 Restaurant A RestaurantB Restaurantc
65 Restaurant A RestaurantB Restaurantc
THIS IS MY REQUIREMENT ::::::
REsname( ie dropdown List ) (Clarity More : That i need to populate Resname w.r.to fid , if restaurant C is not present in fid 63 means Restaurant C should not Get into dropdown list of fid 63)
I need LIKE THIS,,,,,,
fid Resname
56 Restaurant A RestaurantB Restaurantc
63 RestaurantA,REstaurantC
65 RestaurantC
This is my issue......Waitin for Suggestion........
o/p was like this in gridview
fid Resname(Dropdown LIST)
56 Restaurant A RestaurantB Restaurant
56 Restaurant A RestaurantB Restaurantc
56 Restaurant A RestaurantB Restaurantc
56 Restaurant A RestaurantB Restaurantc
63 Restaurant A RestaurantB Restaurantc
63 Restaurant A RestaurantB Restaurantc
63 Restaurant A RestaurantB Restaurantc
63 Restaurant A RestaurantB Restaurantc
65 Restaurant A RestaurantB Restaurantc
THIS IS MY REQUIREMENT ::::::
REsname( ie dropdown List ) (Clarity More : That i need to populate Resname w.r.to fid , if restaurant C is not present in fid 63 means Restaurant C should not Get into dropdown list of fid 63)
I need LIKE THIS,,,,,,
fid Resname
56 Restaurant A RestaurantB Restaurantc
63 RestaurantA,REstaurantC
65 RestaurantC
This is my issue......Waitin for Suggestion........
ASKER
hi .. Good job....
I was able to retrieve using distinct fid ,,
Now last thing which s happening is
am not gettin with index value of fid ..its retrieving my all records of restaurant in dropdown list....
Plz suggest wat can be done.....
I was able to retrieve using distinct fid ,,
Now last thing which s happening is
am not gettin with index value of fid ..its retrieving my all records of restaurant in dropdown list....
Plz suggest wat can be done.....
over here:
if(e.Row.RowType == DataControlRowType.DataRow )
{
//get the ID
string fid = e.Row.Cells[0].Text;
the cell index, you just gotta make sure it gets the right number (looks like it 0 but I dont know what you have infront of it, you can try 1 2 (incase you have edit button before that column)
string fid = e.Row.Cells[2].Text; for example
Put a debug point in there, try to what value it gets.
JINN
if(e.Row.RowType == DataControlRowType.DataRow
{
//get the ID
string fid = e.Row.Cells[0].Text;
the cell index, you just gotta make sure it gets the right number (looks like it 0 but I dont know what you have infront of it, you can try 1 2 (incase you have edit button before that column)
string fid = e.Row.Cells[2].Text; for example
Put a debug point in there, try to what value it gets.
JINN
ASKER
ITs reading CEll VAlue...
Am gettin Damn right cell index valuess...
The only issue is...
with this query i gues....
select fid,(select resname from resttable where rid = maintable.rid)as resname from maintable
This is the query am passing to ddlname ...Ders mistake inside in dis query oly ....
Wats Happenin ITs Retriving all the records to every dropdown list of resname
For eg..
fid
1 as resname 1
2 as resname 1,resname2
3. as resname1
Everey dropdownLIST been populated having values Of resname1,resname1,resname2,resname1
Plz check with the query...u ve been miraculously helpful so far....
Thakssssss a lot......
.
Am gettin Damn right cell index valuess...
The only issue is...
with this query i gues....
select fid,(select resname from resttable where rid = maintable.rid)as resname from maintable
This is the query am passing to ddlname ...Ders mistake inside in dis query oly ....
Wats Happenin ITs Retriving all the records to every dropdown list of resname
For eg..
fid
1 as resname 1
2 as resname 1,resname2
3. as resname1
Everey dropdownLIST been populated having values Of resname1,resname1,resname2,resname1
Plz check with the query...u ve been miraculously helpful so far....
Thakssssss a lot......
.
private void PopulateDropDownListNameByID(string fid, DropDownList ddlname)
{
//query and populate ddlName
string constr = ConfigurationManager.AppSettings["constring"];
SqlConnection myconnection = new SqlConnection(constr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select fid,(select resname from resttable where rid = maintable.rid)as resname from maintable", myconnection);
da.Fill(ds);
ddlname.Items.Clear();
ddlname.DataSource = ds.Tables[0];
ddlname.DataValueField = "fid";
ddlname.DataTextField = "resname";
ddlname.DataBind();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
HEyyyyyyyy THankssssss
U deservee many points than 500 . .......
I was trying this for more than 2 weeks..................... .
No words..... U guysss Rockkkssss.......
Luking for more help.........
Thanksssssssss a lottttttttttttttttttttttt
U deservee many points than 500 . .......
I was trying this for more than 2 weeks.....................
No words..... U guysss Rockkkssss.......
Luking for more help.........
Thanksssssssss a lottttttttttttttttttttttt
ASKER
HEyyyyyyyy THankssssss
U deservee many points than 500 . .......
I was trying this for more than 2 weeks..................... .
No words..... U Rockkkssss.......
Luking for more help.........
Thanksssssssss a lottttttttttttttttttttttt
U deservee many points than 500 . .......
I was trying this for more than 2 weeks.....................
No words..... U Rockkkssss.......
Luking for more help.........
Thanksssssssss a lottttttttttttttttttttttt
ASKER
GReat Explanation...
Very good clarity
Very good clarity
You are welcome, I'd like to think you would do the same for another who might need helps. It's great you work it out.
Glad to help ^^
JINN
Glad to help ^^
JINN
ASKER
definitely. i f am confident
You are and you will be even more ^^
This is the right place ^^
JINN
This is the right place ^^
JINN
ASKER
Since am dealing with diff issue, i had posted my new question, this link ll take u to c my isue
https://www.experts-exchange.com/questions/23865101/Dropdown-List-index-changed-ASp-net-c.html
Thank u...
https://www.experts-exchange.com/questions/23865101/Dropdown-List-index-changed-ASp-net-c.html
Thank u...
select name from table where id= <%#DataBinder.Eval( Container.DataItem, "ID" )%>
Otherwise, refer to another solutions of mine which programatically form code behind:
https://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q__23864429.html
Hope this helps
JINN