Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid with Edit and Multi Select Listbox

Status
Not open for further replies.

timothy

Programmer
Mar 20, 2000
39
US
I have a ASP.Net DataGrid with edit columns. I bring in a list of users with info like account number, custid etc. Everything works fine.

Now I want to add an edit column that contains a multiple select listbox. When the listbox loads I want to select the appropriate items for the user. Anyone know how to do this?

So far I am able to show the listbox with all available choices. So all I need to do now is pick/select the items for the user.

This is my datagrid:
Code:
<asp:datagrid id="dgUsers" runat="server" Width="424px" Height="96px" OnDeleteCommand="dgUsers_Delete" OnItemCommand="dgUsers_ItemCommand" OnEditCommand="dgUsers_Edit" OnCancelCommand="dgUsers_Cancel" OnUpdateCommand="dgUsers_Update"
DataKeyField="USERID" BackColor="Gray" ForeColor="Black" Font-Size="X-Small" Font-Names="Arial"
HorizontalAlign="Center" AllowPaging="True" PageSize="5" AutoGenerateColumns="False">
<HeaderStyle Font-Size="Smaller" Font-Names="Arial" Font-Bold="True" Wrap="False" HorizontalAlign="Center"
ForeColor="Black" VerticalAlign="Middle" BackColor="Red"></HeaderStyle>
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton"   UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn ButtonType="LinkButton" Text="Delete" CommandName="Delete"></asp:ButtonColumn>
<asp:BoundColumn DataField="USER_NAME" HeaderText="User Name"></asp:BoundColumn>
<asp:BoundColumn DataField="UPASSWORD" HeaderText="Password"></asp:BoundColumn>
<asp:BoundColumn DataField="FIRST_NAME" HeaderText="First Name"></asp:BoundColumn>
<asp:BoundColumn DataField="LAST_NAME" HeaderText="Last Name"></asp:BoundColumn>
<asp:BoundColumn DataField="USER_EMAIL" HeaderText="Email"></asp:BoundColumn>
<asp:TemplateColumn ItemStyle-VerticalAlign="Top" HeaderText="Info">

<EditItemTemplate>
[COLOR=blue]
<asp:DropDownList runat="server" id="Groups" DataSource='<%# GetGroups() %>' DataTextField="DESCRIPTION" DataValueField="GID" >
</asp:DropDownList>
[/color]
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="UPDATE_DATE" HeaderText="Last Update" ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn DataField="USERID" HeaderText="Uid" ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn DataField="CUSTID" HeaderText="Cid" ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn DataField="UPDATE_USERID" HeaderText="Update Uid" ReadOnly="True"></asp:BoundColumn>
</Columns>
</asp:datagrid>

Thanks for you thoughts and help.

 
utilize the onitemdatabound event to insert the control and add your logic to select the appropriate items.
 
Thanks, how can I get to the cell I need to change it? For example (dif are of code same type of issue)...

This is how deep I have to go in the DataGrid (highlighted in blue)...

Code:
<Columns>
<asp:TemplateColumn>
  <ItemTemplate>
  <table>
  <tr>
  <td><%# DataBinder.Eval(Container.DataItem, "NAME")%></td>
  </tr>
  <tr>
  <td><%# DataBinder.Eval(Container.DataItem, "CITY")%>
  <%# DataBinder.Eval(Container.DataItem, "STATE")%>
  </td>
  </tr>
[COLOR=blue]
  <tr>
  <td><%# DataBinder.Eval(Container.DataItem, "USL")%></td>
  </tr>
[/color]
  </table>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>

I try this....
Code:
public void ItemDataBoundEventHandler(object sender, DataGridItemEventArgs e){
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem){
string aoru="";
aoru=Convert.ToString(DataBinder.Eval(e.Item.DataItem, "USL"));
if(aoru==""){
[COLOR=blue]e.Item.Cells[0].Text="ASL";[/color]
}else{
[COLOR=blue]e.Item.Cells[0].Text="USL";[/color]
}}}

But it looks like it is only picking up the "<asp:TemplateColumn>" no deeper.

Any idea how I can get to the cell:
<%# DataBinder.Eval(Container.DataItem, "USL")%>
to get at and change the value in it?

Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top