Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more: , +
XML
<asp:DataList ID="dlFav" runat="server" RepeatColumns="4"
            RepeatDirection="Vertical" ondeletecommand="dlFav_DeleteCommand">
    <ItemTemplate>
    <font color="red">Added User:</font><asp:Label ID="lblUserId" runat="server" Text='<%# Eval("AddedUserID") %>'></asp:Label><br />
    <font color="red">ProductID:</font><asp:Label ID="lblProductID" runat="server" Text='<%# Eval("ProductID") %>'></asp:Label><br />
    <font color="red">ProductName:</font><asp:Label ID="lblProductName" runat="server" Text='<%# Eval("ProductName") %>'></asp:Label><br />
    <font color="red">Price:</font><asp:Label ID="lblPrice" runat="server" Text='<%# Eval("Price") %>'></asp:Label><br />
    <font color="red">Image Url:</font><asp:Image ID="ImageUrl" runat="server" ImageUrl='<%#Eval("ImageUrl") %>'></asp:Image>
        <br />
        <asp:CheckBox ID="chkDl" runat="server" Text="Select" 
            CommandName="Select" />
        <br />


    </ItemTemplate>
    </asp:DataList>


XML
<table>
   <tr>
   <td>

       <asp:Button ID="btnadd" runat="server" Text="Add" />
   </td>
   </tr>

    </table>





hi this is my source code.in checkbox click i want to add data to database.,.can any one solve..i want to add multiply data to database while selcting checkbox and while clicking add button i want to save data to database..
Posted
Comments
devbtl 4-Jan-12 2:18am    
you are saving data by clicking checkbox or add btn ?
ythisbug 4-Jan-12 3:54am    
first i want to select checkbox after that i want to click add then only it should add to database..u got my point??
ythisbug 4-Jan-12 4:14am    
is there anyone to help??

 
Share this answer
 
v4
Comments
ythisbug 4-Jan-12 2:10am    
can u give more explanation??
ythisbug 4-Jan-12 3:51am    
bro thanks..bt this is jquery..can u give me asp.net wid c# link..
bool data;

C#
if (CheckBox1.Checked)
{
data=True;
}
else
data=False;


//data value u can save in database
 
Share this answer
 
Comments
ythisbug 4-Jan-12 4:29am    
example..[ProductID][ProductName][Price][Image][checkbox][addbutton]if i select and click to add button then only it should add to database.....
Rupa1 11-Jan-12 5:56am    
using findcontrol u can find [Checkbox] using that...we can get it.........
you can simply do it by defining your checkbox in rowdatabound of gridview and then pass the checkbox value to query.
C#
CheckBox chk1 = (CheckBox)GridView1.FooterRow.FindControl("chk1");
CheckBox chk2 = (CheckBox)GridView1.FooterRow.FindControl("chk2");

string chk1,chk2;
if ((chk1.Checked == true) && (chk2.Checked == true))
           {
               chk1 = "1";
               chk2 = "1";
           }
           else
           {
               if (chk1 .Checked == true)
               {
                   chk1 = "1";
                   chk2= "0";
               }
               else
                   if (chk2.Checked == true)
                   {
                       chk1 = "0";
                       chk2= "1";
                   }

           }

and use these values into ur insert query

for checkbox insertion
SQL
select cast('" + chk1+ "' + ',' + '" + chk2+ "' as varchar(100)) as db_column from tablename
 
Share this answer
 
v3
Comments
ythisbug 4-Jan-12 4:27am    
i need code for datalist..
ythisbug 4-Jan-12 4:28am    
example..[ProductID][ProductName][Price][Image][checkbox][addbutton]if i select and click to add button then only it should add to database.....
In your btnadd_Click event
foreach (DataListItem item in DataList1.Items)
            {
               
                CheckBox chk = (CheckBox)item.FindControl("CheckBox1");
                if (chk.Checked == true)
                {
                    //save data to database.
}
            }
 
Share this answer
 
Comments
ythisbug 4-Jan-12 5:37am    
foreach (DataListItem item in DataList1.Items)
{
CheckBox chk = (CheckBox)item.FindControl("CheckBox1");
if (chk.Checked == true)
{
string UserID = "";
string ProductID = "";
string ProductName = "";
string Price = "";
string ImageUrl = "";




ProductID = lblProduct.Text;
ProductName = lblName.Text;
Price = lblPrice.Text;
ImageUrl = imgImage.ImageUrl;

@madhu m getting error here..like lblName doesnot exist like for all label too..
m@dhu 4-Jan-12 7:38am    
You got to use findcontrol method to find all those labels and image, as it is for checkbox. Like
Label lblUSerID=(Label)item.FindControl("lblUserId");

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