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

GridTemplateColumn with chackbox

2 Answers 40 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ghadeer
Top achievements
Rank 1
ghadeer asked on 06 Jan 2009, 10:05 AM
Hi All,

I want to switch fro gridview to RadGrid ,I have two bound field and a checkbox in a templatecolumn , I want to check all the grid rows for checked box and get the bound value for the checked one ,how can I do that with RadGrid?????

the button codebehind for the old gridview:

int

iCheckCount=0;
for (int iRows = 0; iRows < grdUserRequestHistory.Rows.Count; iRows++)

 

{

 

 

GridViewRow row = grdUserRequestHistory.Rows[iRows];

 

 

 

bool isChecked = ((CheckBox)row.FindControl("chkUsers")).Checked;

 

 

 

if (isChecked)

 {

iCheckCount = 1;

 

string strHospCd = string.Empty;

  

 

switch (row.Cells[0].Text)

{

 

 

case "NMC":

 

strHospCd =

 

"'00'"

 

break;  

 

case "RCH":

strHospCd =

 

"'01'";  

 

break

 

case "RNH":

strHospCd =

 

"'02'" 

 

 

break;

 

}

 

 

 

 

 

 

// I will insert data here 

 

}

}


thanks in advance
ghadeer

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 06 Jan 2009, 11:22 AM
Hello Ghadeer,

You can try out the following code to achieve the required scenario.
aspx:
    <telerik:GridTemplateColumn HeaderText="Template Column" UniqueName="TemplateColumn"
        <ItemTemplate>       
            <asp:CheckBox ID="CheckBox" Checked='<%# (DataBinder.Eval(Container.DataItem,"Discontinued").ToString()%>' runat="server" /> 
        </ItemTemplate>        
        </telerik:GridTemplateColumn> 
 
 <telerik:GridBoundColumn DataField="ProductName" HeaderText="ProductName" UniqueName="ProductName" > 
 </telerik:GridBoundColumn>        
 

cs:
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridDataItem dataItem in RadGrid1.Items) 
        { 
            CheckBox chkbx = (CheckBox)dataItem["TemplateColumn"].FindControl("CheckBox"); 
            if (chkbx.Checked) 
            { 
                string strtxt = dataItem["ProductName"].Text; 
            } 
        } 
   } 

Thanks
Princy.
0
Daniel
Telerik team
answered on 06 Jan 2009, 11:24 AM
Hello Ghadeer,

Try the following approach:
protected void Button1_Click(object sender, EventArgs e) 
    CheckBox cb; 
    foreach (GridDataItem item in radGrid.MasterTableView.Items) 
        cb = (CheckBox)item.FindControl("chkUsers"); 

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
ghadeer
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or