This is a migrated thread and some comments may be shown as answers.

[Solved] how to check checkbox value inside another table ?

1 Answer 99 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David Blok
Top achievements
Rank 1
David Blok asked on 10 Dec 2009, 12:31 PM


Using the following code on aspx :

<telerik:RadGrid ID="RadGrid1" Width="100%" AllowColumnsReorder="True" AllowPaging="True" AutoGenerateColumns="True" PageSize="5" runat="server" AllowSorting="true" GridLines="None" ShowStatusBar="true" AllowMultiRowSelection="True">  
  <MasterTableView Width="100%" AllowRowSelect="true">  
<Columns> 
  <telerik:GridTemplateColumn> 
        <HeaderTemplate> 
         SELECT  
        </HeaderTemplate> 
        <ItemTemplate> 
            <asp:CheckBox id="CheckBox1" DataField="ID" OnCheckedChanged="ToggleRowSelection" AutoPostBack="True" runat="server"></asp:CheckBox> 
        </ItemTemplate> 
    </telerik:GridTemplateColumn> 
 
  <telerik:GridImageColumn DataType="System.String" DataImageUrlFields="Filename" 
        DataImageUrlFormatString="~/Upload/Images/Mediaitems/{0}" AlternateText="Customer image" ImageAlign="Middle" ImageWidth="110px"   
        HeaderText="Image Column" FooterText="ImageColumn footer" UniqueName="Picturename"/>  
          
  <telerik:GridTemplateColumn> 
        <HeaderTemplate> 
         Delete image  
        </HeaderTemplate> 
        <ItemTemplate> 
            <asp:CheckBox id="CheckBox2" OnCheckedChanged="DeleteRowSelection" AutoPostBack="True" runat="server"></asp:CheckBox> 
        </ItemTemplate> 
    </telerik:GridTemplateColumn> 
</Columns> 
</MasterTableView>   
  <PagerStyle Mode="NextPrevAndNumeric" /> 
    <FilterMenu EnableTheming="True">  
        <CollapseAnimation Duration="200" Type="OutQuint" /> 
    </FilterMenu> 
</telerik:RadGrid> 

Populate the data :
Protected Sub RadGrid1_NeedDataSource(ByVal source As ObjectByVal e As GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource  
 
        RadGrid1.DataSource = GetDataTable("SELECT * FROM TblMediaitems")  
 
    End Sub 
 
 
    Public Function GetDataTable(ByVal query As StringAs DataTable  
        Dim ConnString As String = ConfigurationManager.ConnectionStrings("varoDb").ConnectionString  
        Dim conn As SqlConnection = New SqlConnection(ConnString)  
        Dim adapter As SqlDataAdapter = New SqlDataAdapter  
        adapter.SelectCommand = New SqlCommand(query, conn)  
        Dim table1 As New DataTable  
        conn.Open()  
        Try 
            adapter.Fill(table1)  
        Finally 
            conn.Close()  
        End Try 
        Return table1  
    End Function 

How can i loop true the datagrid and check the value of "CheckBox1" with another database to set it to true or false ?

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 10 Dec 2009, 07:25 PM
Hello David,

Simplified code-snippet is shown below. Try this approach locally and let me know if you need further assistance.
protected void Button1_Click(object sender, EventArgs e)
{
    foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
    {
        bool isChecked = (item.FindControl("CheckBox1") as CheckBox).Checked;
        //...
    }
}
 
Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
David Blok
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or