Hi Ken,
Here's the code:
<asp:datagrid id="dgAssignMM" runat="server" Width="100%"
Font-Size="X-Small" BackColor="White" Font-Names="Tahoma" PageSize="20"
AutoGenerateColumns="False" BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" CellPadding="1" DataKeyField="no">
<SelectedItemStyle Font-Bold="True" ForeColor="Black"
BackColor="LightCoral"></SelectedItemStyle>
<EditItemStyle BackColor="LightCoral"></EditItemStyle>
<AlternatingItemStyle
BackColor="MistyRose"></AlternatingItemStyle>
<ItemStyle ForeColor="#330099"
BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC"
BackColor="#A51C44"></HeaderStyle>
<FooterStyle ForeColor="#330099"
BackColor="#FFFFCC"></FooterStyle>
<Columns>
<asp:TemplateColumn HeaderText="Action"
ItemStyle-VerticalAlign=Top >
<HeaderStyle Wrap="False" HorizontalAlign="Center"
Width="10%"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:ImageButton id="Imagebutton6" runat="server"
AlternateText="Edit Data" Imageurl="../images/edit_mm.gif"
CommandName="edit"></asp:ImageButton>
<asp:ImageButton id="ImageButton5" runat="server"
AlternateText="Edit Data" Imageurl="../images/Delete_mm.gif"
CommandName="delete"></asp:ImageButton>
</ItemTemplate>
<EditItemTemplate>
<asp:ImageButton id="Imagebutton7" runat="server"
AlternateText="Save Data" Imageurl="../images/save_mm.gif"
CommandName="update"></asp:ImageButton>
<asp:ImageButton id="Imagebutton8" runat="server"
AlternateText="Cancel Updates" Imageurl="../images/Cancel_mm.gif"
CommandName="cancel"></asp:ImageButton>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="DIR UserID"
ItemStyle-VerticalAlign=Top>
<HeaderStyle Wrap="False"
HorizontalAlign="Center"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<%# Container.DataItem("dir_id") %>
</ItemTemplate>
<EditItemTemplate>
<asp
ropDownList id="ddlDIR_ID" runat="server"
Font-Size="8pt" SelectedIndex='<%#
GetSelectedIndex("dir_id",Container.DataItem("dir_id")) %>'
DataValueField="dir_id" DataTextField="dir_id"
DataSource='<%#GetSource("dir_id")%>'>
</asp
ropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="MM Head UserID"
ItemStyle-VerticalAlign=Top >
<HeaderStyle Wrap="False"
HorizontalAlign="Center"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<%# Container.DataItem("mm_head") %>
</ItemTemplate>
<EditItemTemplate>
<asp
ropDownList id="ddlMM_head" runat="server"
Font-Size="8pt" SelectedIndex='<%#
GetSelectedIndex("mm_head",Container.DataItem("mm_head")) %>'
DataValueField="mm_head" DataTextField="mm_head"
DataSource='<%#GetSource("mm_head")%>'>
</asp
ropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="MM UserID"
ItemStyle-VerticalAlign=Top>
<HeaderStyle Wrap="False"
HorizontalAlign="Center"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<%# Container.DataItem("username") %>
</ItemTemplate>
<EditItemTemplate>
<asp
ropDownList id=ddlName runat="server"
Font-Size="8pt" DataValueField="username" DataTextField="username"
DataSource='<%#GetSource("username")%>' SelectedIndex='<%#
GetSelectedIndex("username",Container.DataItem("username")) %>'>
</asp
ropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Cust Sector"
ItemStyle-VerticalAlign=Top>
<HeaderStyle Wrap="False"
HorizontalAlign="Center"></HeaderStyle>
<ItemTemplate>
<%# Container.DataItem("custsector")%>
</ItemTemplate>
<EditItemTemplate>
<asp
ropDownList id="ddlCustSector" runat="server"
Font-Size="8pt" DataValueField="custsector" DataTextField="custsector"
DataSource='<%#GetSource("custsector")%>' SelectedIndex='<%#
GetSelectedIndex("custsector",Container.DataItem("custsector")) %>'>
</asp
ropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Industry Code"
ItemStyle-VerticalAlign=Top >
<HeaderStyle Wrap="False"
HorizontalAlign="Center"></HeaderStyle>
<ItemTemplate>
<%# Container.DataItem("industry_code")%>
</ItemTemplate>
<EditItemTemplate>
<asp
ropDownList id="ddlIndustry_code"
runat="server" Font-Size="8pt" DataValueField="Industry_Code"
DataTextField="Industry_Code" DataSource='<%#GetSource("Industry_Code")%>'
SelectedIndex='<%#
GetSelectedIndex("Industry_Code",Container.DataItem("Industry_Code")) %>'>
</asp
ropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="SVC_AMG"
ItemStyle-VerticalAlign=Top>
<HeaderStyle Wrap="False"
HorizontalAlign="Center"></HeaderStyle>
<ItemTemplate>
<%# Container.DataItem("svc_amg")%>
</ItemTemplate>
<EditItemTemplate>
<asp
ropDownList id="ddlsvc_amg" runat="server"
Font-Size="8pt" DataValueField="svc_amg" DataTextField="svc_amg"
DataSource='<%#GetSource("svc_amg")%>' SelectedIndex='<%#
GetSelectedIndex("svc_amg",Container.DataItem("svc_amg")) %>'>
</asp
ropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Country"
ItemStyle-VerticalAlign=Top>
<HeaderStyle Wrap="False"
HorizontalAlign="Center"></HeaderStyle>
<ItemTemplate>
<%# Container.DataItem("country")%>
</ItemTemplate>
<EditItemTemplate>
<asp
ropDownList id="ddlCountry" runat="server"
Font-Size="8pt" DataValueField="country" DataTextField="country"
DataSource='<%#GetSource("country")%>' SelectedIndex='<%#
GetSelectedIndex("country",Container.DataItem("country")) %>'>
</asp
ropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="custsector Test"
ItemStyle-VerticalAlign=Top>
<HeaderStyle Wrap="False"
HorizontalAlign="Center"></HeaderStyle>
<ItemTemplate>
<asp:Label ID="lblCustSector"><%#
Container.DataItem("custsector")%></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:ListBox ID=lstCustSector Runat=server
Font-Size="8pt" DataValueField="custsector" DataTextField="custsector"
DataSource='<%#GetSource("custsector")%>'></asp:ListBox>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099"
BackColor="#FFFFCC"></PagerStyle>
</asp:datagrid>
Public Function GetSource(ByVal col As String)
Dim dt As New DataTable()
Select Case col.ToLower
Case "dir_id"
dt = CorpHandler.GetMMUsername("dir_id", "")
Case "mm_head"
dt = CorpHandler.GetMMUsername("mm_head", "")
Dim newRow As DataRow
newRow = dt.NewRow
newRow(0) = ""
dt.Rows.Add(newRow)
Case "username"
dt = CorpHandler.GetMMUsername("username", "")
Dim newRow As DataRow
newRow = dt.NewRow
newRow(0) = ""
dt.Rows.Add(newRow)
Case "custsector"
dt = CorpHandler.GetMMCustSector
Dim newRow As DataRow
newrow = dt.NewRow
newrow(0) = "ALL"
dt.Rows.InsertAt(newrow, 0)
Case "industry_code"
dt = CorpHandler.GetMMIndustryCode
Dim newRow As DataRow
newrow = dt.NewRow
newrow(0) = "ALL"
dt.Rows.InsertAt(newrow, 0)
Case "svc_amg"
dt = CorpHandler.GetMMSVC_AMG
Dim newRow As DataRow
newrow = dt.NewRow
newrow(0) = "ALL"
dt.Rows.InsertAt(newrow, 0)
Case "country"
dt = CorpHandler.GetMMCountry
Dim newRow As DataRow
newrow = dt.NewRow
newrow(0) = "ALL"
dt.Rows.InsertAt(newrow, 0)
End Select
Return dt
End Function
Function GetSelectedIndex(ByVal col As String, ByVal value As Object) As
Integer
Dim bEmpty As Boolean = False
Dim row As DataRow
Dim iLoop As Integer
Dim iSel As Integer = -1
Dim sData As String
Dim sValue As String
Dim dt As New DataTable()
dt = GetSource(col)
For iLoop = 0 To dt.Rows.Count - 1
If IsDBNull(dt.Rows(iLoop)(col)) Then
sData = "-9999"
Else
sData = dt.Rows(iLoop)(col)
End If
If IsDBNull(value) Then
sValue = "-9999"
Else
sValue = value.ToString.Trim.ToUpper
End If
If sValue = sData Then
'Return iLoop
iSel = iLoop
Exit For
End If
Next iLoop
If iSel = -1 Then
For iLoop = 0 To dt.Rows.Count - 1
If IsDBNull(dt.Rows(iLoop)(col)) Then
sData = "-9999"
Else
sData = dt.Rows(iLoop)(col)
End If
If sData = "" Then
Return iLoop
End If
Next
Else
Return iSel
End If
dt.Dispose()
End Function
Private Sub dgAssignMM_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgAssignMM.ItemCommand
Dim lbx As ListBox
Dim lbxitm As ListItem
Dim itm As DataGridItem
Dim arr As Array
itm = e.Item
'lbx = e.Item.FindControl("lstCustSector")
'e.Item.Cells(9).FindControl("lstcustsector")
arr = Split(CType(e.Item.FindControl("lblCustSector"), Label).Text,
",")
' don't know what to put here .. as i can't get the control..
End Sub
in display, custsector is in label control. Only after pressing EDIT, we
will display in listbox with its multiple selection selected .. but i still
have no idea how to get those selected value from label to listbox.
Thanks
rgds,
Lie