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,
Anupam KakkarPosted Aug 12, 2011, 1:03 PM
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...
Suthish NairPosted Jul 30, 2011, 3:10 AM
Dorababu MekaPosted Jul 29, 2011, 11:56 PM
Anupam KakkarPosted Jul 29, 2011, 4:27 PM
How do I close the thread?
Anupam KakkarPosted Jul 29, 2011, 12:52 PM
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
Zoran HorvatPosted Jul 29, 2011, 3:32 AM
Zoran