Hi,
I' having some problems with binding data to a checkbox in a WebDataGrid.
I tried a few things myself, and for some reason I just cant get it to work, Basicly i'm looking for something like:
preview of my WebDataGrid: http://img41.imageshack.us/f/permissionsb.png/
I got Users, wich on check get permissions, so when I check an checkbox for a user in his row, OnClick add permission I want to add permission by wich loopin through the WebDataGrid and all checkboxes wich are checked need to be added.
If any1 could explain how to do this, or show me an example
I'd really appriciate it
Dim cb As CheckBox Dim dgi As DataGridItem Dim idList As String = ""
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click For Each dgi In WebDataGrid1.Items cb = CType(dgi.Cells(CB_Algemeen).Controls(1), CheckBox) If cb.Checked Then Dim permissionController As New Permissions.PermissionController() Dim chkList As CheckBoxList = DirectCast(sender, CheckBoxList) chkList.DataSource = permissionController.GetPermissionByCodeAndKey("SYSTEM_TAB", "VIEW") chkList.DataTextField = "PermissionName" chkList.DataValueField = "PermissionID" chkList.DataBind() End If Next End Sub
<ig:WebDataGrid ID="WebDataGrid1" runat="server" EnableAjax="False" Height="350px" Width="637px" AutoGenerateColumns="False"> <Columns> <ig:BoundDataField DataFieldName="UserID" Key="UserID" Hidden="True"> <Header Text="UserID" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="Username" Key="Username" Width="90px"> <Header Text="Username" /> </ig:BoundDataField> <ig:TemplateDataField Key="Algemeen" Width="90px"> <ItemTemplate> <div style="text-align: center;"> <asp:CheckBox runat="server" ID="Algemeen" /></div> </ItemTemplate> <HeaderTemplate> <div style="text-align: center;"> <asp:Label ID="Label3" runat="server" Text="Algemeen"></asp:Label> <input type="checkbox" name="SelectAlgemeen" onclick="Check(this);" /> </div> </div> </HeaderTemplate> </ig:TemplateDataField> <ig:TemplateDataField Key="Financieel" Width="90px"> <ItemTemplate> <div style="text-align: center;"> <asp:CheckBox runat="server" ID="Financieel" /></div> </ItemTemplate> <HeaderTemplate> <div style="text-align: center;"> <asp:Label ID="Label3" runat="server" Text="Financieel"></asp:Label> <input type="checkbox" name="SelectFinancieel" onclick="Check(this);" /> </div> </div> </HeaderTemplate> </ig:TemplateDataField> <ig:TemplateDataField Key="Licentie" Width="90px"> <ItemTemplate> <div style="text-align: center;"> <asp:CheckBox runat="server" ID="Licentie" /></div> </ItemTemplate> <HeaderTemplate> <div style="text-align: center;"> <asp:Label ID="Label3" runat="server" Text="Licentie"></asp:Label> <input type="checkbox" name="SelectLicentie" onclick="Check(this);" /> </div> </div> </HeaderTemplate> </ig:TemplateDataField> <ig:TemplateDataField Key="Applicatie" Width="90px"> <ItemTemplate> <div style="text-align: center;"> <asp:CheckBox runat="server" ID="Applicatie" /></div> </ItemTemplate> <HeaderTemplate> <div style="text-align: center;"> <asp:Label ID="Label3" runat="server" Text="Applicatie"></asp:Label> <input type="checkbox" name="SelectApplicatie" onclick="Check(this);" /> </div> </div> </HeaderTemplate> </ig:TemplateDataField> <ig:TemplateDataField Key="UitDienst" Width="90px"> <ItemTemplate> <div style="text-align: center;"> <asp:CheckBox runat="server" ID="UitDienst" /></div> </ItemTemplate> <HeaderTemplate> <div style="text-align: center;"> <asp:Label ID="Label3" runat="server" Text="Uit Dienst"></asp:Label> <input type="checkbox" name="SelectUitDienst" onclick="Check(this);" /> </div> </div> </HeaderTemplate> </ig:TemplateDataField> </Columns></ig:WebDataGrid>
Visual Basic Code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim userInfo As UserInfo userInfo = UserController.GetCurrentUserInfo() If userInfo.UserID = -1 Then End If Company = userInfo.Profile.GetPropertyValue("Company") Dim strSQLconnection As String = ("Data Source=.\SQLExpress;Initial Catalog=dnn2;User ID=vb1;Password=Klompsrv1") cSQL = "SELECT Users.UserID, Users.Username, UserProfile.PropertyValue FROM ProfilePropertyDefinition INNER JOIN UserProfile ON ProfilePropertyDefinition.PropertyDefinitionID = UserProfile.PropertyDefinitionID INNER JOIN Users ON UserProfile.UserID = Users.UserID WHERE (ProfilePropertyDefinition.PropertyName = 'Company') AND (UserProfile.PropertyValue = '" + Company + "')" Dim sqlConnection As New SqlConnection(strSQLconnection) Dim sqlCommand As New SqlCommand(cSQL, sqlConnection) Dim SqlAdapter As New SqlDataAdapter(sqlCommand) Dim DataSet As New DataSet() SqlAdapter.Fill(DataSet) If sqlConnection.State = ConnectionState.Closed Then sqlConnection.Open() End If WebDataGrid1.DataSource = DataSet WebDataGrid1.DataBind() End Sub
With an ASP checkbox in your markup, you can use the following code to access the value of those checkboxes.
DirectCast(WebDataGrid.Rows(rowindex).Items(columnindex).FindControl("Checkbox1"),Checkbox).Checked
You can loop through the rows and increment rowindex or you can use a for each.
Ed
how would it be for a username then?
I trierd DirectCast(WebDataGrid.Rows(rowindex).Items(columnindex).FindControl("Username").Value()
but that doesnt work
Crea