Rajar Ahmed
asked on
datagrid dropdownlist..
this is the same code am using without a datagrid , i mean this code works fine indivudally,
in other pagee i ve datagrid ,in edit template i ve three dropdown list , same result to b shown . as in code. but am not able to find id of dropdownlist . and also how can i do , selected change of dropdownlist in datagrid .......??
in other pagee i ve datagrid ,in edit template i ve three dropdown list , same result to b shown . as in code. but am not able to find id of dropdownlist . and also how can i do , selected change of dropdownlist in datagrid .......??
protected void ddlcity_SelectedIndexChanged(object sender, EventArgs e)
{
string code = ddlcity.SelectedValue.ToString();
string constr = ConfigurationManager.AppSettings["cons"];
SqlConnection con1 = new SqlConnection(constr);
SqlCommand recipename = new SqlCommand("select hid,recipe from recipetable where cid='" + code + "'", con1);
SqlDataAdapter da_recipe = new SqlDataAdapter(recipename);
DataSet ds = new DataSet();
da_recipe.Fill(ds);
ddlrecipe.DataSource = ds;
ddlrecipe.DataTextField = "recipe";
ddlrecipe.DataValueField = "hid";
ddlrecipe.Items.Clear();
ddlrecipe.DataBind();
SqlCommand restname = new SqlCommand("select resttable.*,resname from resttable where hid='" + code + "'", con1);
SqlDataAdapter da_restname = new SqlDataAdapter(restname);
DataSet ds1 = new DataSet();
da_restname.Fill(ds1);
ddlres.DataSource = ds1;
ddlres.DataTextField = "resname";
ddlres.DataValueField = "rid";
ddlres.Items.Clear();
ddlres.DataBind();
}
protected void ddlrecipe_SelectedIndexChanged(object sender, EventArgs e)
{
string code = ddlrecipe.SelectedValue.ToString();
string constr = ConfigurationManager.AppSettings["cons"];
SqlConnection con1 = new SqlConnection(constr);
SqlCommand restname = new SqlCommand("select resttable.*,resname from resttable where hid='" + code + "'", con1);
SqlDataAdapter da_restname = new SqlDataAdapter(restname);
DataSet ds1 = new DataSet();
da_restname.Fill(ds1);
ddlres.DataSource = ds1;
ddlres.DataTextField = "resname";
ddlres.DataValueField = "rid";
ddlres.Items.Clear();
ddlres.DataBind();
}
----------------------------------------
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Am getting this error...
Both DataSource and DataSourceID are defined on 'DropDownList1'. Remove one definition.
Both DataSource and DataSourceID are defined on 'DropDownList1'. Remove one definition.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I removed datasourceid but still get that error message..
asp:TemplateColumn HeaderText="City">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" Style="position: relative" DataSourceID="SqlDataSource1" DataTextField="city" DataValueField="cid" AppendDataBoundItems="true" SelectedItem='<%# Bind("city") %>' OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Text="Change ur City" Value="0" />
</asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:tonivtreepConnectionString2 %>"
SelectCommand="SELECT * FROM [citytable]"></asp:SqlDataSource>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="DropDownList1"
ErrorMessage="Please Select any City" Style="position: relative" InitialValue="0">*</asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Style="position: relative" Text='<%# Bind("city") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="recipe">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Style="position: relative" Text='<%# Bind("recipe") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" Style="position: relative" AppendDataBoundItems="true" >
<asp:ListItem Text="Change ur Recipe" Value="0" />
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="DropDownList2"
ErrorMessage="Please Select Any Recipe" InitialValue="0" Style="left: 0px; position: relative;
top: -2px" Width="11px">* </asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="restaurant">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Style="position: relative" Text='<%# Bind("resname") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList3" runat="server" Style="position: relative" AppendDataBoundItems="true" >
<asp:ListItem Text="Change Your restaurant" Value="0"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="DropDownList3"
ErrorMessage="Please Select any Restaurant" InitialValue="0" Style="position: relative">*</asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateColumn>
ASKER
I had pasted the necessary things...
If its not enough i ll posttt the entire page....
I want the selected changed of dropdown list should happen inside the datagrid....
i dunno how to proceed.....
Open in new window