Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
protected void Button1_Click1(object sender, EventArgs e)
 {for (int i = 0; i < GridView1.Rows.Count; i++)
     {
         CheckBox chkUpdate = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
         if (chkUpdate != null)
         {
             if (chkUpdate.Checked)
             {

                 
                 con.Open();
                 Label ID = (Label)GridView1.Rows[i].FindControl("Label7");
                 Session["ID1"] = ID.Text;
                 Label GatePassNo = (Label)GridView1.Rows[i].FindControl("Label1");

                 Label Customer_Name = (Label)GridView1.Rows[i].FindControl("Label2");

                 Label Customer_Location = (Label)GridView1.Rows[i].FindControl("Label3");

                 Label Product_Name = (Label)GridView1.Rows[i].FindControl("Label4");

                 Session["Asst"] = Product_Name.Text;
                 Label SerialNo = (Label)GridView1.Rows[i].FindControl("Label5");

                // con.Open();
               

                  
                             // con.Close();
                             //Button Add = (Button)PreviousPage.FindControl("Button2");
                             con.Close();

                             string qry = "insert into abc (Asset_Type,ID)values('"  + Product_Name.Text + "','" +ID.Text + "')";
                             SqlCommand comd = new SqlCommand(qry, con);
                             con.Open();
                         
                             comd.ExecuteNonQuery();
                             using (SqlCommand comm = new SqlCommand("select [Asset_Type] from abc where ID=@ID", con))
                             {

                                 // 2. define parameters used in command object
                                 SqlParameter para = null;
                                 para = new SqlParameter();
                                 para.ParameterName = "@ID";
                                 para.Value = ID.Text;
                                 comm.Parameters.Add(para);

                                 //Pass @Pages parameter

                                 SqlDataReader reade = comm.ExecuteReader();
                                 while (reade.Read())
                                 {
                                     Session["Asset_Type"] = Convert.ToString(reade["Asset_Type"]);
                                 }
}
}
public void bindddl()
{
    con.Open();
    string qry = " Select Vendor_Name from vendor where Asset_Type in ('"+Session["Asset_Type"]+"')";
        SqlDataAdapter adpt = new SqlDataAdapter(qry,con);
    DataTable dt = new DataTable();
    adpt.Fill(dt);
        DropDownList4.DataSource= dt;
    DropDownList4.DataBind();
    DropDownList4.DataTextField="Vendor_Name";
    DropDownList4.DataValueField="Vendor_Name";
    con.Close();
}

Hi Every one this is my code. My problem is how to retrieve the Vendor Name from vendor that are common to the assets selected in gridview.
Vendor database contains
Vendor_Name      Asset_Type
Futuresoft	Motherboard
Futuresoft	SMPS
Future India	HDD
Future India	joystick
Future India	Laptop Screen
Tech_M	        Baterry
Tech_M	        Laptop Screen
Tech_M	        Mouse
dgd	        Battery
ryy	        Battery
ryy	        HDD
ryy	        joystick
Religare	HDD
Religare	joystick
Religare	Mouse
Religare	Processor
Religare	RAM

how will i bind the vendor names in drop down list that are common to all the Asset type. Suppose in gridview i selected three Assets such HDD and joystick and laptop screen then drop down list should contain Future India because this vendor contains three assets. How will i do this please help
Posted
Updated 2-Jul-14 2:22am
v2

Just make coma(,) separated string of Asset_Type id like '1,2,3,4,5,6,7,8' and pass it to the procedure.
Make one store procedure which accept the id of Asset_Type in string like '1,2,3,4,5,6,7,8'.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[SP_getAllVendorDetails]
(
	@Asset_TypeID varchar(max)
)
As
Begin
		EXEC(
'select distinct(Vendor_Name) FROM vendor  WHERE Asset_TypeID IN (' + @List + ')'
)
End


so it will return distinct vendor list
 
Share this answer
 
Comments
Member 10578683 3-Jul-14 1:49am    
please give the c#code
Bhushan Mehetre 3-Jul-14 2:19am    
protected void Button1_Click1(object sender, EventArgs e)
{
string Asset_Type = "";
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chkUpdate = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
if (chkUpdate != null)
{
if (chkUpdate.Checked)
{
///find the asset type id and append it to the string
///Asset_Type+= <asset_type id="">+",";
}
}
}
char chkcoma=Asset_Type[Asset_Type.Length-1];
if (chkcoma==',')
Asset_Type = Asset_Type.Remove(Asset_Type.Length - 1, 1);
///Now pass Asset_Typeto procedure and get vendor name

}
Member 10578683 3-Jul-14 2:37am    
Thanks
First create one function which will take particular items and return vendors name.
then just call the function when checkbox is checked or unchecked fromthe grid.

To reduce postback you can first make selection of checkboxes and then on another button click get the values of all selected ceckboxes items and pass it to the function which will return you the vendor list.
Bid the return vendor list to the drop down list.
you are done.
 
Share this answer
 
v2
Comments
Member 10578683 2-Jul-14 9:58am    
Can you give some code for it.
Member 10578683 2-Jul-14 10:05am    
how will i get the common vendor name

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