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
Solved

DataGrid and CheckList Binding

Posted on 2004-04-21
2
1,006 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
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

Suggested Solutions

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 .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

792 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