TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
manoj kumar
NA
147
139.8k
Re CheckBoxList
Dec 16 2009 3:03 AM
Hi I am Insert Multiple validate CheckBoxList in sql 2005.I have problum this code...
pls help m...
using
System;
using
System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.Data.SqlClient;
using
System.Data.SqlTypes;
public
partial
class
_Default
: System.Web.UI.
Page
{
string
Strlist, Strlist1;
protected
void
Page_Load(
object
sender,
EventArgs
e)
{
}
private
bool
validate()
{
int
counter = 0;
foreach
(
ListItem
li
in
checkBoxList1.Items)
{
if
(li.Selected)
{
counter = counter + 1;
Strlist = Strlist +
" "
+ li.Text;
}
}
if
(counter > 2)
{
return
false
;
}
else
{
return
true
;
}
}
private
bool
validate1()
{
int
counter = 0;
foreach
(
ListItem
li
in
CheckBoxList2.Items)
{
if
(li.Selected)
{
counter = counter + 1;
Strlist1 = Strlist1 +
" "
+ li.Text;
}
}
if
(counter > 2)
{
return
false
;
}
else
{
return
true
;
}
}
private
bool
check()
{
if
(validate1())
{
return
true
;
}
else
{
return
false
;
}
if
(validate())
{
return
true
;
}
else
{
return
false
;
}
}
protected
void
button1_Click(
object
sender,
EventArgs
e)
{
if
(check())
{
string
data =
ConfigurationManager
.ConnectionStrings[
"manoj"
].ConnectionString;
SqlConnection
con =
new
SqlConnection
(data);
SqlCommand
cmd =
new
SqlCommand
(
"insert into tabn(Country,City)values(@Country,@City)"
, con);
cmd.Parameters.Add(
"@Country"
,
SqlDbType
.VarChar).Value = checkBoxList1.SelectedItem.ToString();
cmd.Parameters.Add(
"@City"
,
SqlDbType
.VarChar).Value = Strlist1;
cmd.Connection = con;
try
{
con.Open();
cmd.ExecuteNonQuery();
Response.Write(
true
);
}
catch
(
Exception
ex)
{
throw
ex;
}
}
else
{
Response.Write(
false
);
}
}
}
If We are not use validate then insert value bt we use validation then give me some error pls help me........
Reply
Answers (
2
)
Asp .Net
How to get template control in datagrid useing in javascript in asp.net?