farjack1
asked on
gridview dropdownlist selected value problem
I am using framework 3.5
i have a gridview its working good in this i have template column having dropdownlist when i am clicking Edit button then dropdownlist come but the value that was in the label in the same cell do not select from dropdownlist please tell me code example.
Thanks
i have a gridview its working good in this i have template column having dropdownlist when i am clicking Edit button then dropdownlist come but the value that was in the label in the same cell do not select from dropdownlist please tell me code example.
Thanks
ASKER
1st Link
i need to assign value in testGridView_RowEditing event
2nd link
there is no selectedvalue property in gridview
i need to assign value in testGridView_RowEditing event
2nd link
there is no selectedvalue property in gridview
ASKER
i am waiting for answer
Thanks
Thanks
Do you want to view the text written in label as Selected Value of the dropdown??
HI farjack1,
You can assign the SelectedValue property like
<asp:TemplateField HeaderText="Test1">
<ItemTemplate>
<asp:Label ID="TestLabel" runat="server" Text='<%# Bind("ItemLabel") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="EditDdl" runat="server" SelectedValue='<%# Bind("BindValue") %>' >
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
You can assign the SelectedValue property like
<asp:TemplateField HeaderText="Test1">
<ItemTemplate>
<asp:Label ID="TestLabel" runat="server" Text='<%# Bind("ItemLabel") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="EditDdl" runat="server" SelectedValue='<%# Bind("BindValue") %>' >
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
ASKER
Actully i mentioned above SelectedValue property is not avaiable in
<EditItemTemplate>
<asp:DropDownList id="ddlProductName" runat="server"
DataTextField="ProductName " DataValueField="ID" DataSource='<%# loadProducts %>'
/>
</EditItemTemplate>
if i put that SelectedValue='<%# Bind("ProductName") %>' under dropdownlist tag then runtime error comes
System.Web.HttpException was unhandled by user code
ErrorCode=-2147467259
Message="DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'ProductName'."
Source="System.Web"
StackTrace:
at System.Web.UI.DataBinder.G etProperty Value(Obje ct container, String propName)
at System.Web.UI.DataBinder.E val(Object container, String[] expressionParts)
at System.Web.UI.DataBinder.E val(Object container, String expression)
at System.Web.UI.TemplateCont rol.Eval(S tring expression)
at ASP.default_aspx.__DataBin ding__cont rol10(Obje ct sender, EventArgs e) in C:\working\ASPProject\Defa ult.aspx:l ine 21
at System.Web.UI.Control.OnDa taBinding( EventArgs e)
at System.Web.UI.WebControls. ListContro l.OnDataBi nding(Even tArgs e)
at System.Web.UI.WebControls. ListContro l.PerformS elect()
at System.Web.UI.WebControls. BaseDataBo undControl .DataBind( )
at System.Web.UI.Control.Data BindChildr en()
InnerException:
if i remove SelectedValue='<%# Bind("ProductName") %>' then works fine but value not selected as required
<EditItemTemplate>
<asp:DropDownList id="ddlProductName" runat="server"
DataTextField="ProductName
/>
</EditItemTemplate>
if i put that SelectedValue='<%# Bind("ProductName") %>' under dropdownlist tag then runtime error comes
System.Web.HttpException was unhandled by user code
ErrorCode=-2147467259
Message="DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'ProductName'."
Source="System.Web"
StackTrace:
at System.Web.UI.DataBinder.G
at System.Web.UI.DataBinder.E
at System.Web.UI.DataBinder.E
at System.Web.UI.TemplateCont
at ASP.default_aspx.__DataBin
at System.Web.UI.Control.OnDa
at System.Web.UI.WebControls.
at System.Web.UI.WebControls.
at System.Web.UI.WebControls.
at System.Web.UI.Control.Data
InnerException:
if i remove SelectedValue='<%# Bind("ProductName") %>' then works fine but value not selected as required
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi farjack1,
U have given the wrong field to bind for the SelectedValue property...
Change it to
EditItemTemplate>
<asp:DropDownList id="ddlProductName" runat="server"
DataTextField="ProductName " DataValueField="ID" DataSource='<%# loadProducts %>'
SelectedValue ='<%# Bind("ID") %>' />
</EditItemTemplate>
U have given the wrong field to bind for the SelectedValue property...
Change it to
EditItemTemplate>
<asp:DropDownList id="ddlProductName" runat="server"
DataTextField="ProductName
SelectedValue ='<%# Bind("ID") %>' />
</EditItemTemplate>
Hi farjack1,
Did u try with the above said change?
Did u try with the above said change?
http://msdn.microsoft.com/en-us/library/ms178294(VS.80).aspx