Click here to Skip to main content
15,888,461 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: __doPostBack('','') Microsoft JScript runtime error:: Object expected Pin
anilpal30-Mar-09 20:29
anilpal30-Mar-09 20:29 
QuestionPlease help me on Production Issue Pin
Member 311097030-Mar-09 0:24
Member 311097030-Mar-09 0:24 
AnswerRe: Please help me on Production Issue Pin
Christian Graus30-Mar-09 0:26
protectorChristian Graus30-Mar-09 0:26 
AnswerRe: Please help me on Production Issue Pin
anilpal30-Mar-09 0:30
anilpal30-Mar-09 0:30 
GeneralRe: Please help me on Production Issue Pin
Member 311097030-Mar-09 1:02
Member 311097030-Mar-09 1:02 
GeneralRe: Please help me on Production Issue Pin
anilpal30-Mar-09 1:06
anilpal30-Mar-09 1:06 
GeneralRe: Please help me on Production Issue Pin
Member 311097030-Mar-09 1:22
Member 311097030-Mar-09 1:22 
QuestionCrisis with a dynamically created drop down list Pin
scar_face30-Mar-09 0:05
scar_face30-Mar-09 0:05 
Here's the deal!

I'm creating two drop down lists dynamically in a GridView control and populating the second dropdownlist(let's call it ddl2 from now on) on the basis of the selection on the first dropdownlist control. The crisis is that, for multiple rows on the gridview the ddl2 starts appending values to itself and therefore ends up having repeats of the data it should originally hold.

How do I stop this repeat from happening? My code is as below.
<asp:GridView ID="grd" runat="server" OnRowDataBound="grd_RowDataBound">           <Columns>        <asp:TemplateField HeaderText="names">             <ItemTemplate>            <asp:DropDownList ID="name" runat="server" OnSelectedIndexChanged="onSelectChangeddl"></asp:DropDownList>          </ItemTemplate>          </asp:TemplateField>          <asp:TemplateField HeaderText="age">           <ItemTemplate>          <asp:DropDownList ID="age" runat="server" AutoPostBack="true">           </asp:DropDownList>            </ItemTemplate>          </asp:TemplateField>    </Columns>          </asp:GridView>



In c# code, i am trying to change the values of the second drop down list based on the value selected in the first. I am doing this as below:

foreach (GridViewRow row in grd.Rows)   {   DropDownList ddl1 = (DropDownList)row.FindControl("name");   DropDownList ddl = (DropDownList)row.FindControl("age");       if (ddl.SelectedValue.ToString() != "---Select---")     {     }     else          {     ddl.Items.Clear();     }           SqlCommand SPComm = new SqlCommand("someStoredProcedure", myConn);     SPComm.CommandType = CommandType.StoredProcedure;     SqlParameter param = SPComm.Parameters.Add("@something", SqlDbType.NVarChar, 50);     param.Value = something;     dr = SPComm.ExecuteReader();  //dr is sqlDataReader     int i = 0;     while (dr.Read())     {     ddl.Items.Insert(i, dr.GetString(0));     }     dr.Close();     ddl.Items.Insert(0, "---Select---");     }  



In the above code, all the values in the second drop down list are getting duplicated based on the selected index changed event handler of the first drop down list.

Can anyone help me with this? Been trying all kinds of stuff with this since three weeks now! H-e-L-p!

scarface

AnswerRe: Crisis with a dynamically created drop down list Pin
anilpal30-Mar-09 0:16
anilpal30-Mar-09 0:16 
QuestionGridview hyprlink column should navigate to two pages Pin
Praneeth Babu K29-Mar-09 23:22
Praneeth Babu K29-Mar-09 23:22 
AnswerRe: Gridview hyprlink column should navigate to two pages Pin
anilpal30-Mar-09 0:03
anilpal30-Mar-09 0:03 
GeneralRe: Gridview hyprlink column should navigate to two pages Pin
Praneeth Babu K30-Mar-09 0:11
Praneeth Babu K30-Mar-09 0:11 
GeneralRe: Gridview hyprlink column should navigate to two pages Pin
anilpal30-Mar-09 0:20
anilpal30-Mar-09 0:20 
GeneralRe: Gridview hyprlink column should navigate to two pages Pin
Praneeth Babu K30-Mar-09 0:31
Praneeth Babu K30-Mar-09 0:31 
Questionpop3 mail Pin
aspnetloves29-Mar-09 23:03
aspnetloves29-Mar-09 23:03 
AnswerRe: pop3 mail Pin
Christian Graus29-Mar-09 23:07
protectorChristian Graus29-Mar-09 23:07 
GeneralRe: pop3 mail Pin
aspnetloves29-Mar-09 23:24
aspnetloves29-Mar-09 23:24 
GeneralRe: pop3 mail Pin
Christian Graus30-Mar-09 0:27
protectorChristian Graus30-Mar-09 0:27 
GeneralRe: pop3 mail Pin
bhattiprolu30-Mar-09 0:45
bhattiprolu30-Mar-09 0:45 
QuestionPopulate records from pop-up to main window!!! Pin
Sr...Frank29-Mar-09 22:56
Sr...Frank29-Mar-09 22:56 
AnswerRe: Populate records from pop-up to main window!!! Pin
anilpal30-Mar-09 0:13
anilpal30-Mar-09 0:13 
GeneralRe: Populate records from pop-up to main window!!! Pin
Sr...Frank30-Mar-09 1:02
Sr...Frank30-Mar-09 1:02 
QuestionASP.net Web Forms Pin
nilam247729-Mar-09 22:26
nilam247729-Mar-09 22:26 
AnswerRe: ASP.net Web Forms Pin
Christian Graus29-Mar-09 22:30
protectorChristian Graus29-Mar-09 22:30 
Questiongetting next xml node value Pin
bhattiprolu29-Mar-09 21:48
bhattiprolu29-Mar-09 21:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.