Hi all,
I've got an editable datagrid with various extra dropdownlist controls which I have added into template columns like so
<asp:TemplateColumn HeaderText="Project">
<EditItemTemplate>
<asp
ropDownList id="ddlProject" DataSource="<%# getProjects() %>" OnPreRender="setddlProjectIndex" DataTextField="ProjectName" DataValueField="ProjectIdKey" runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>
I have no trouble retrieving the value that the user selected when saving their changes which I do in the Datagrid's OnUpdate method
public void OnUpdate(Object source, DataGridCommandEventArgs e)
{
...
int iProjectId = Convert.ToInt32(((DropDownList)e.Item.FindControl("ddlProject")).SelectedValue);
...
}
So that's all fine. My problem is that I don't know how to set the selected value of the drop down list in the first place, as soon as the user clicks the edit button. As you can see I suspect I need to have a method which is called on the drop down's OnPreRenderEvent (I've called it setddlProjectIndex here although I haven't written any code).
Can someone tell me how to set the selected value to the value that's already in the database please?
Thanks for any help you can give.
cheers,
Sarah
I've got an editable datagrid with various extra dropdownlist controls which I have added into template columns like so
<asp:TemplateColumn HeaderText="Project">
<EditItemTemplate>
<asp
</EditItemTemplate>
</asp:TemplateColumn>
I have no trouble retrieving the value that the user selected when saving their changes which I do in the Datagrid's OnUpdate method
public void OnUpdate(Object source, DataGridCommandEventArgs e)
{
...
int iProjectId = Convert.ToInt32(((DropDownList)e.Item.FindControl("ddlProject")).SelectedValue);
...
}
So that's all fine. My problem is that I don't know how to set the selected value of the drop down list in the first place, as soon as the user clicks the edit button. As you can see I suspect I need to have a method which is called on the drop down's OnPreRenderEvent (I've called it setddlProjectIndex here although I haven't written any code).
Can someone tell me how to set the selected value to the value that's already in the database please?
Thanks for any help you can give.
cheers,
Sarah