Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to loop the subscription list from the database.

At the same time, I loop the specific user's subscription request.

For example, in the subscription list, there are several items, says

System Analyst
System Developer
System Manager
System Tester

In the subscription list, the user subscribed 2 of them, says

System Manager
System Tester

In the looping, I will loop a table with a checkbox column to show all the subscription value.

I encounter a problem here.

I want to make the checkbox "checked" while the user has subscribed the item.

For example, the result of table should have "checked" 2 of the checkbox.

However, I don't know the algorithm to implement my logic.

Can anyone kindly provide some hints for me to realize this?
Posted
Comments
Member 11185927 9-Dec-14 1:24am    
I write a coding to get checkbox value as boolaen but that values are stored as '0' i dont know what mistake i had done there &nwhere anybody helpme out........

if(source==creat)
{
try
{
t=0;
//flag=0;
ResultSet rs1 = reg.st.executeQuery("select * from emp where id='"+b+"'");
while(rs1.next())
{
t=1;
}
if(t==0)
{
jp.showMessageDialog(this,"Sorry, Not a Valid Employee Id","INFORMATION",jp.ERROR_MESSAGE);
t=0;
//flag=1;
}
//c.close();
//stm.close();
}

catch(SQLException sql)
{
jp.showMessageDialog(this,sql,"EXCEPTION",jp.ERROR_MESSAGE);
}
//if(flag==0)
//{
if((uname.getText().length()!=0)&&(pass.getText().length()!=0))
{
try
{
t=0;
for(i=0;i<13;i++)
<!--13--> // s[i]=emid[i].isSelected();
{
if(jc.isSelected())
{
jc.setSelected(true);

}
else if(jc1.isSelected())
{
jc1.setSelected(true);
}
else if(jc2.isSelected())
{
jc2.setSelected(true);
}
else if(jc3.isSelected())
{
jc3.setSelected(true);
}
else if(jc4.isSelected())
{
jc4.setSelected(true);
}
else if(jc5.isSelected())
{
jc5.setSelected(true);
}
else if(jc6.isSelected())
{
jc6.setSelected(true);
}
else if(jc7.isSelected())
{
jc7.setSelected(true);
}
else if(jc8.isSelected())
{
jc8.setSelected(true);
}
else if(jc9.isSelected())
{
jc9.setSelected(true);
}
else if(jc10.isSelected())
{
jc10.setSelected(true);
}
else if(jc11.isSelected())
{
jc11.setSelected(true);
}
else if(jc12.isSelected())
{
jc12.setSelected(true);
}

}

t=0;


reg.st.executeUpdate("insert into perm(name,pass,ait,eit,aem,eem,gen,can,pay,dws,bal,dds,nil,ema,ate) values('"+a+"','"+d+"','"+a2+"','"+a3+"','"+a4+"','"+a5+"','"+a6+"','"+a7+"','"+a8+"','"+a9+"','"+a10+"','"+a11+"','"+a12+"','"+a13+"','"+a14+"')");
jp.showMessageDialog(this,"Permissions are Given ","SUCCESS",jp.INFORMATION_MESSAGE);

//c.close();
//stm.close();
}

catch(SQLException sql)
{
jp.showMessageDialog(this,sql,"EXCEPTION",jp.ERROR_MESSAGE);
}
}
else
jp.showMessageDialog(this,"Please Fill User Name and Password","SUCCESS",jp.INFORMATION_MESSAGE);
}
how to check whether the checkbox value checked or not and stores in a database

1 solution

Hi,

try this
C#
  if(dt.rows[0][3].tostring().startswith("Checked"))
{
 Checkbox2.Checked=true;
}
else
{
Checkbox2.Checked=false;
}


for e.g

your table has columns like

SubscribeTab with columns UserID,Analyst,Developer,Manager,Tester

Then If user has only Manager and Tester then

you can retrieve data from database based on id then your result table contains

for e.g
231,No,No,Checked,Checked

so just you can use above method for that.

you can follow same meethod for storing also

All the Best
 
Share this answer
 
v2
Comments
sriranganadhk 20-Oct-11 10:46am    
If u dont mine will u plz Explain me...
i have two tables.
and How to get the values here...
Thanks in advance..
Muralikrishna8811 20-Oct-11 10:48am    
mention your table design
Muralikrishna8811 20-Oct-11 10:49am    
b'coz you wanna more clear right.so with table desing I can elaborate it
sriranganadhk 20-Oct-11 11:10am    
first table
sno designation
1 System Analyst
2 System Developer
3 System Manager
4 System Tester
2nd table

sno username permission
1 xyz System Analyst
2 abc System Developer

now,at desingn page get all designations
in that if user have paermission those visible in checked checkbox

ex:
xyz have permission to see system analist page
checkbox with checked system analist
check box develeper
check box Programmer

like that iam new to asp plz help me out..
Muralikrishna8811 20-Oct-11 11:23am    
you mean you've four checkboxes in design page right?

then username is stored in session variable

you can retrieve data based on your 2nd table

like

select permission from 2ndtable where username=sessionvariable

now you've table data with permissions

In desing page checkboxes has values like as
first Checkbox value is Analyst
second Checkbox value is Developer
and so on...

now dt has result data right

for(int i=0;i<dt.rows.count;i++)
{
foreach(Checkbox chb in Checkboxlist1)
{
if(chb.value.indexOf(dt.rows[0][0].tostring())>0)
{
chb.checked=true;
}
else
{
chb.checked=false;
}
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900