5 Answers, 1 is accepted
You can check out the following code to access the value of a CheckBox on clicking a button outside the grid.
cs:
protected void Button1_Click(object sender, EventArgs e) |
{ |
foreach (GridDataItem item in RadGrid2.MasterTableView.Items) |
{ |
foreach (GridColumn col in RadGrid2.MasterTableView.RenderColumns) |
{ |
if (col.UniqueName == "ToandFro") |
{ |
CheckBox chkbx = (CheckBox)item["ToandFro"].Controls[0]; |
string strtxt = chkbx.Checked.ToString(); |
} |
} |
} |
} |
Thanks
Princy.
Thanks for you help
I want the selected row of checkbox value.
You can try out the code snippet given below and see if it meets your requirement.
aspx:
<telerik:GridClientSelectColumn UniqueName="SelectCol"></telerik:GridClientSelectColumn> |
cs:
protected void Button1_Click(object sender, EventArgs e) |
{ |
foreach (GridItem item in RadGrid2.SelectedItems) |
{ |
GridDataItem dataitem = (GridDataItem)item; |
CheckBox chkbx = (CheckBox)dataitem["SelectCol"].Controls[0]; |
} |
} |
Thanks
Shinu.
Hi, this is my C# code
protected void BtnUnlock_Click(object sender, EventArgs e)
{
if (HiddenField1.Value != "")
{
// if using Microsoft Grid,the code can get Checkbox value
//bool bIsLocked = ((CheckBox)GridView1.Rows[GridView1.SelectedIndex].Cells[9].Controls[0]).Checked;
// Error code: get checkbox value(datatyp: bit)
bool bIsLocked = ((CheckBox)RadGrid1.Rows[RadGrid1.SelectedIndex].Cells[5].Controls[0]).Checked;
if (bIsLocked) //Locked
{
MembershipUser u;
string strUserName = this.RadGrid1.SelectedValue.ToString();
u = Membership.GetUser(strUserName);
string connstring = ConfigurationManager.ConnectionStrings["CBPCConnectionString"].ConnectionString;
using (SqlConnection dataConnection = new SqlConnection(connstring))
{
dataConnection.Open();
SqlCommand dataCommand = new SqlCommand("aspnet_Membership_UnlockUser");
dataCommand.Connection = dataConnection;
dataCommand.CommandType = CommandType.StoredProcedure;
dataCommand.Parameters.Add(new SqlParameter("@ApplicationName", SqlDbType.NVarChar));
dataCommand.Parameters.Add(new SqlParameter("@UserName", SqlDbType.NVarChar));
dataCommand.Parameters[0].Value = "CBPC";
dataCommand.Parameters[1].Value = strUserName;
SqlDataReader reader = dataCommand.ExecuteReader();
reader.Close();
dataConnection.Close();
}
//this.RadGrid1.DataSource = SqlDataSource1;
this.RadGrid1.Rebind();
//发送邮件
MailMessage m_message = new MailMessage();
m_message.From = new MailAddress("cbpc_vcis@hq.cofcoko.com");
m_message.To.Add(new MailAddress(u.Email));
m_message.Subject = "From P-VCIS";
string MailBody = "Hi," + strUserName + "\r\n:";
MailBody = MailBody + "Your account has been unlocked .";
m_message.Body = MailBody;
SmtpClient m_smtpClient = new SmtpClient();
m_smtpClient.Send(m_message);
}
}
else
{
this.Label2.Text = "No Selecting!";
}
}
Here I have tried with a CheckBox in the ItemTemplate of a GridTemplateColumn. On clicking the Button I am trying to access the CheckBox from the selected rows of the Grid.
CS:
protected void Button1_Click(object sender, EventArgs e) |
{ |
foreach (GridItem item in RadGrid1.SelectedItems) |
{ |
GridDataItem dataitem=(GridDataItem)item; |
CheckBox chkbx = (CheckBox)dataitem["CheckCol1"].FindControl("CheckBox1"); |
bool BoolVal = chkbx.Checked; |
} |
} |
ASPX:
<telerik:GridTemplateColumn UniqueName="CheckCol1" HeaderText="CheckCol1" > |
<ItemTemplate> |
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%#Eval("CheckCol1") %>'/> |
</ItemTemplate> |
</telerik:GridTemplateColumn> |
Thanks
Princy.