Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DataGrid and CheckList Binding

Posted on 2004-04-21
2
Medium Priority
?
1,028 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 400 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

636 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