Solved

DataGrid and CheckList Binding

Posted on 2004-04-21
2
1,021 Views
Last Modified: 2008-02-01
Hi All,

W have requirement like this:

We have a datagrid which display the data from a DBUsers Table.

Each row in the datagrid will have a "Edit" link, and on click of  "Edit", the row data will become editable and "Update" and "Cancel" link gets displayed for that row instead of "Edit" link.

One of the column data returns the access codes in the form of "1" and "0", for example 10001. Each characters represent whether user has got access ( if its "1") or not( if its "0") for a particular operation i.e. add, delete, update etc etc. I want to display the this column value in a <ASP:CheckBoxList> control, so when user clicks on "Edit" link, the access code value "10001", will be displayed as five checkboxes.

I could able to display the check boxes, but I wanted to know how can I check/uncheck the check box depending on the access code string. For example for access code string "10001", the first and fifth checkbox should be displayed as checked and others unchecked. How can I do that.

The code for datagrid is as as follows:

----------------------------------------------------------------------------------------------------
<form id="WebForm2" method="post" runat="server">
<ASP:DataGrid id="UserDBDataGrid" runat="server" CellPadding="2" EditItemStyle-BackColor="yellow" DataKeyField="EMAILID" OnEditCommand="OnEdit" OnUpdateCommand="OnUpdate" OnCancelCommand="OnCancel" OnDeleteCommand="OnDelete" AutoGenerateColumns="False">
<Columns>
<ASP:TemplateColumn HeaderText="Access Permission">
<ItemTemplate>
 <ASP:Label Text='<%# DisplayAccessList(Convert.ToString(DataBinder.Eval (Container.DataItem, "ACCESSCODE"))) %>' runat="server" ID="LabelAccessPerm" />
</ItemTemplate>
<EditItemTemplate>
<ASP:CheckBoxList ID="access_checkboxlist" DataValueField="Value" DataTextField="Key" DataSource='<%# GetHashAccessCode(Convert.ToString(DataBinder.Eval(Container.DataItem, "ACCESSCODE"))) %>' RepeatDirection="Horizontal" runat="server" >
</ASP:CheckBoxList>
</EditItemTemplate>
</ASP:TemplateColumn>
<ASP:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" />
</Columns>
</ASP:DataGrid>
</form>
----------------------------------------------------------------------------------------------------

Here the GetHashAccessCode() function  returns HashTable name/value pair for the CheckBoxList control.

Thanks in advance,
Lilu

0
Comment
Question by:lilupat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 28

Accepted Solution

by:
mmarinov earned 100 total points
ID: 10876397
you can do this only manually
create ItemDataBound event for the datagrid

public void dgDrafts_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem )
  {
    CheckBoxList cbl = (CheckBoxList)e.Item.FindControl("access_checkboxlist");
    Label l = (Label)e.Item.FindControl("LabelAccessPerm");
     if ( cbl != null && l != null )
      {
        for ( int i=0; i < cbl.Items.Count; i++)
          {
              if ( l.Text.Substring(i,1) == "1") cbl.Items[i].Selected = true;
          }
       }
  }
}

HTH
B..M
0
 

Author Comment

by:lilupat
ID: 10887466
That's great a answer. Its working fine for me . Thanks a lot ....
Lilu
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question