I am facing an issue in GridView using a DropDownList. Please help me, I would appreciate it a lot!
legacy_emblem test1
legacy_emblem test2
legacy_emblem test3
The above is the data I need to insert into a GridView.
Here is how I want it.
So, looking at the GridView is should show only 1 Row, like this:
but instead, it shows all the 3 Rows. Also, The DropDownList shows items Vertically and not Horizontally,
like this:
t
e
s
t
1
How do I do it.
Thanks,

Zoran HorvatRank #792 · 2.9K reputationPosted Jul 28, 2011, 11:32 PM EDT
Zoran
Anupam Kakkar10 reputationPosted Jul 29, 2011, 8:52 AM EDT
All the rows are unique, only first column is replicating.
Here is the code you asked for.
For .cs file
if (_option != null) {
GridViewOption.DataSource = _option; GridViewOption.DataBind();
}
For .aspx file
ItemStyle-HorizontalAlign="Right"
ItemStyle-Width="1%"
ItemStyle-Wrap="false">
ItemStyle-HorizontalAlign="Right"
ItemStyle-Width="1%"
ItemStyle-Wrap="false">
AutoPostBack="true" DataSource='<%# Eval("ElementName", "{0:s}") %>' Width="200px">
_option is a List for Type
Anupam Kakkar10 reputationPosted Jul 29, 2011, 12:27 PM EDT
How do I close the thread?
Dorababu MekaRank #457 · 5.5K reputationPosted Jul 29, 2011, 7:56 PM EDT
Suthish NairRank #92 · 22.8K reputationPosted Jul 29, 2011, 11:10 PM EDT
Anupam Kakkar10 reputationPosted Aug 12, 2011, 9:03 AM EDT
I used entirely a new method of resolving the problem:
ASPX Page
onrowdatabound="GridViewOption_RowDataBound"
SkinId="CartOption"
>
ItemStyle-HorizontalAlign="Left"
ItemStyle-Width="1%"
ItemStyle-Wrap="false">
ItemStyle-HorizontalAlign="Left"
ItemStyle-Width="1%"
ItemStyle-Wrap="false">
AutoPostBack="true"
Width="200px">
ASPX.CS PAGE
protected void GridViewOption_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex > -1)
{
DropDownList ItemOptionDropDown = e.Row.Cells[1].FindControl("txtitemid") as DropDownList;
Label ItemOptionLabel = e.Row.Cells[1].FindControl("labeloptions") as Label;
try
{
CartOpt = this.GetCartOption((int)DataBinder.Eval(e.Row.DataItem, "StoreId"), DataBinder.Eval(e.Row.DataItem, "ItemId").ToString());
if (CartOpt.Count > 0)
{
ItemOptionLabel.Text = DataBinder.Eval(e.Row.DataItem, "ItemId").ToString();
foreach (CartOptionInfo ctop in CartOpt)
{
ItemOptionDropDown.Items.Add(ctop.ElementName);
}
}
else
e.Row.Visible = false;
}
catch
{
// No Exception Thrown
}
}
}
Thats how I did it. Hope it helps...