Solved

DataGrid and CheckList Binding

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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