Click here to Skip to main content
14,454,989 members
Rate this:
Please Sign up or sign in to vote.
See more:
i done this coding but i cant find that what is the mistake....

==>two listbox ==> lst_leftstar and lst_rightstar
items pass from lst_leftstar to lst_rightstar
and
coding for ==>> lst_rightstar values store in database.

==>> 2 tables
==> <1> starmaster
starid
star

==>> <2> profile star
profilestar
starid

xml query is perfect written
but problem is in the coding..
my code is :=

protected void btnsumit_partner_details_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();

        dt.Columns.Add("Star_Id");

        for (int i = 0; i < lst_rightstar.Items.Count; i++)
        {
            dt.Rows.Add("");

            dt.Rows[i]["Star_Name"] = lst_rightstar.Items[i].Value;
        }

        clsregisterinfo.Dtstd = dt;
        clsregisterinfo.insert_data();
    }

==> my problm is here.
that when id debug i see that...for loop isn't worked..
means...when i trace the code...i cant enter in for loop..
and vales pass null in class file.
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

Even though your question is bit vague, but as per my understanding problem is as below and this is the reason why its not entering the for loop

I think you are trying to move item from the lst_leftstar to lst_rightstar, and when at the start you will try to move an item from left to right, the right listbox will be empty i.e. item.count = 0. hence it will not enter for loop.

and I think you replace this
Quote:
for (int i = 0; i < lst_rightstar.Items.Count; i++)


with

for (int i = 0; i < lst_leftstar.Items.Count; i++)


I hope it will solve your problem of not entering in for loop.

Further inside the loop there is a mistake of column mismatch.

on the start you are adding a column named Star_Id
Quote:
dt.Columns.Add("Star_Id");
while inside the loop you are trying to enter value in
Quote:
dt.Rows[i]["Star_Name"]


i.e. Column Named as Star_Name which you have not added before..

Hope it will help you.. :)
   
Comments
Manish Dalwadi 20-Feb-14 3:56am
   
sorry dr...i forgot to tell you..that
i move items from lst_leftstar to lst_rightstar using javascript(doubleclick)
.
this coding is just only for insert lst_rightstar items un database..
and i have this problem(for loop)


protected void btnsumit_partner_details_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();

dt.Columns.Add("Star_Id");

for (int i = 0; i < lst_rightstar.Items.Count; i++)
{
dt.Rows.Add("");

dt.Rows[i]["Star_Id"] = lst_rightstar.Items[i].Value;
}

clsregisterinfo.Dtstd = dt;
clsregisterinfo.insert_data();
}

please chek it again
Rate this:
Please Sign up or sign in to vote.

Solution 2

sorry dr...i forgot to tell you..that
i move items from lst_leftstar to lst_rightstar using javascript(doubleclick)
.
this coding is just only for insert lst_rightstar items in database..
and i have this problem(for loop)


protected void btnsumit_partner_details_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
 
        dt.Columns.Add("Star_Id");
 
        for (int i = 0; i < lst_rightstar.Items.Count; i++)
        {
            dt.Rows.Add("");
 
            dt.Rows[i]["Star_Id"] = lst_rightstar.Items[i].Value;
        }
 
        clsregisterinfo.Dtstd = dt;
        clsregisterinfo.insert_data();
    }


please check it again or loop
   
v3
Comments
VICK 20-Feb-14 6:53am
   
Have you solved this problem ?? if not than do not "Accept This as solution" to get the answers from others.or else this post will loose focus.
VICK 20-Feb-14 6:56am
   
clsregisterinfo.Dtstd = dt;
clsregisterinfo.insert_data();

???What these lines are doing?? What is clsregisterinfo ?? some helper class?? & Dtstd ??? is this variable setting datasource to be set for inserting data???
Manish Dalwadi 20-Feb-14 23:05pm
   
clsregisterinfo is a claas file in this i pass these selected items
and Dtstd is a datatable property in classfile..i pass the datatable in dtstd in classfile clsregisterinfo..

.

dr.
i think problem is theere..that
i moving items from lst_leftstar to lst_rightstar using javascript(double click event)

<script type="text/javascript"> /* star */
function lst_left_star_DblClicked() {
var left_lst = document.getElementById("<%=lst_leftstar.ClientID%>");
var right_lst = document.getElementById("<%=lst_rightstar.ClientID%>");

for (var i = 0; i < left_lst.length; i++) {
if (left_lst.options[i].selected == true) {
right_lst.options[right_lst.length] =
new Option(left_lst.options[i].text,
left_lst.options[i].value);
left_lst.options[i] = null;
i = i - 1;
}
}
return;
}
</script>
javascript is completely work and other coding is above

but may be its a client side ...not convert into server side...
i have no idea about this..
   
Not an answer. Abuse.
—SA

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100