Please help
Hi everyone,
I am fairly new to ASP.NET programming and am working on a small project where I have to create an intranet portal where people can update their skills. I am using data grid to populate my data using Web Matrix tool. I am running into 2 problems when I convert a default text box when users click on Edit into a combo box:
1-Combo box doesnt automatically select the prepolulated data
2-Is there a way to write a better code than what I have below as I have to do this for 10 different datagrid on the same page and each datagrid has 5 different dropdowns edits.
I would really appreciate any help and feedback in this: Here is a sample code I have:
<asp:DataGrid id="dgLanguage" runat="server" Width="393px" Font-Names="Times New Roman" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" BackColor="White" CellPadding="3" GridLines="None" AutoGenerateColumns="False" Font-Size="X-Small" OnEditCommand="dgLanguage_Edit" OnUpdateCommand="dgLanguage_Update" OnCancelCommand="dgLanguage_Cancel" CellSpacing="1">
<FooterStyle forecolor="Black" backcolor="#C6C3C6"></FooterStyle>
<SelectedItemStyle font-bold="True" forecolor="White" backcolor="#9471DE"></SelectedItemStyle>
<ItemStyle forecolor="Black" backcolor="#DEDFDE"></ItemStyle>
<HeaderStyle font-bold="True" forecolor="#E7E7FF" backcolor="#4A3C8C"></HeaderStyle>
<Columns>
<asp:BoundColumn Visible="False" DataField="ResLangID" ReadOnly="True" HeaderText="ResLangID"></asp:BoundColumn>
<asp:BoundColumn DataField="SkillName" ReadOnly="True" HeaderText="Language Name"></asp:BoundColumn>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "writing") %>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddl3" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlSelectionChanged">
<asp:ListItem Value="0">None</asp:ListItem>
<asp:ListItem Value="1">Working Knowledge</asp:ListItem>
<asp:ListItem Value="2">Good</asp:ListItem>
<asp:ListItem Value="3">Fluent</asp:ListItem>
<asp:ListItem Value="4">Native</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
</Columns>
<PagerStyle horizontalalign="Right" forecolor="Black" backcolor="#C6C3C6"></PagerStyle>
</asp:DataGrid>
Protected Sub ddlSelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ddl As DropDownList,dd2 As DropDownList,dd3 As DropDownList,dd4 As DropDownList,dd5 As DropDownList
ddl = CType(sender, DropDownList)
dd2 = CType(sender, DropDownList)
dd3 = CType(sender, DropDownList)
dd4 = CType(sender, DropDownList)
dd4 = CType(sender, DropDownList)
'Label3.Text = ddl.SelectedItem.Text
End Sub
|