Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi guys,

I have a repeater,
where i have a dropdownlist n textbox.

onselectedindexchanged event of ddl, i want to fill the specific textbox.

may be using clientid or else....

plz suggest me;

ASP CODE:
<asp:Repeater ID="Repeater1" runat="server"
                                   onitemdatabound="Repeater1_ItemDataBound">
                                   <HeaderTemplate>
                                       <table class="table table-striped table-bordered" id="a0">
                                       <thead>
                                       <tr>
                                           <th>DoorNo#</th>
                                           <th>PlateNo#</th>
                                           <th>Status</th>
                                           <th>Driver</th>
                                           <th>Department</th>
                                           <th>Location</th>
                                       </tr>
                                   </thead>
                                       <tbody>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                           <tr class="odd gradeX">
                                               <td>
                                                   <asp:Label ID="lbldoorno" runat="server" Text='<%# Eval("DoorNo")%>'></asp:Label></td>
                                               <td><asp:Label ID="lblplateno" runat="server" Text='<%# Eval("PlateNo")%>'></asp:Label></td>
                                               <td><asp:DropDownList ID="ddlstatus" OnSelectedIndexChanged="ddldept_SelectedIndexChanged"
                                                AutoPostBack="true" Width="100px" runat="server">
                                                   <asp:ListItem Value="1"> Active </asp:ListItem>
                                                   <asp:ListItem Value="2"> InActive</asp:ListItem>
                                                   </asp:DropDownList></td>
                                               <td><asp:TextBox ID="txtdriver" runat="server" Text="a"></asp:TextBox></td>
                                               <td>
                                                   <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                                                   <ContentTemplate>
                                                   <asp:DropDownList ID="ddldept" runat="server">
                                                   </asp:DropDownList>
                                                   </ContentTemplate>
                                                   <Triggers>
                                                   <asp:PostBackTrigger ControlID="ddldept" />
                                                   <%--<asp:PostBackTrigger ControlID="ddldept" />--%>
                                                   </Triggers>
                                                   </asp:UpdatePanel>
                                               </td>
                                               <td><asp:TextBox ID="txtlocation" Text="yard" runat="server"></asp:TextBox></td>

                                           </tr>
                                    </ItemTemplate>
                                    <FooterTemplate>
                                       <table width="100%">
                                       <tbody><tr><td align="center"><br />
                                           <asp:Button ID="btnCncl" runat="server" Text="Cancel" CssClass="btn btn-danger btn-small"  Font-Bold="True" onclick="ButtonCncl_Click"  />
                                            
                                           <asp:Button ID="btnSave" runat="server" CssClass="btn btn-success btn-small" Text="Save" Font-Bold="True" onclick="ButtonSave_Click" /></td></tr></tbody>
                                       </table>
                                    </FooterTemplate>
                                   </asp:Repeater>


my code:

protected void ddldept_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList d = (DropDownList)sender;
            //TextBox t = (TextBox)sender;
            
            int index = Convert.ToInt32(d.SelectedValue);

            if (index == 2)
            {
                TextBox tb = FindControl("txtdriver") as TextBox;
               tb.text ="N/a";
                TextBox tbl = FindControl("txtlocation") as TextBox;
                tbl.Textt = "Yard";
            }
            // Use d here
        }


plz help me.... ...


thanks
Posted
Updated 7-May-20 20:30pm
v3
Comments
Krunal Rohit 15-Feb-14 10:20am    
Okay, so what is the error ?
abdul subhan mohammed 15-Feb-14 10:22am    
NullReferenceException,

i want to fill it by using clientid/any suggestions...

just the requirement is to fill the textbox on selected dropdownlist changed...
Krunal Rohit 15-Feb-14 10:41am    
That TextBox Id is correct ?
abdul subhan mohammed 15-Feb-14 10:48am    
i have a textbox in a repeater,

even i tried findcontrol("repeater1").findcontrol("txtdriver") as textbox;

but still not working...

Dear Subhan,

Repeater control is used to display repeating pattern of data like grid or lists

Examples:
http://www.w3schools.com/aspnet/aspnet_repeater.asp

and

msdn.microsoft.com/en-us/magazine/cc163780.aspx

I am not sure what do you want to achieve by adding a single text box to it, I suggest creating Item templates and then bind the data to those item templates.

Hope this helps

Regards
Omer.
 
Share this answer
 
Comments
[no name] 15-Feb-14 23:04pm    
Yes you are right
C#
protected void ddldept_SelectedIndexChanged(object sender, EventArgs e)
{
if(!IsPostBack)
    {
        DropDownList d = (DropDownList)sender;
         //TextBox t = (TextBox)sender;
                    
          int index = Convert.ToInt32(d.SelectedValue);
         
                    if (index == 2)
                    {
                        TextBox tb = FindControl("txtdriver") as TextBox;
                       tb.text ="N/a";
                        TextBox tbl = FindControl("txtlocation") as TextBox;
                        tbl.Textt = "Yard";
                    }
        }
}
 
Share this answer
 
Comments
abdul subhan mohammed 15-Feb-14 10:38am    
bad try!, not working!
abdul subhan mohammed 15-Feb-14 10:40am    
textbox tb = findcontrol("txtdriver") as textbox;

is getting null, its not finding this "txtdriver"...

that's y i'm nullreferenceexception...
You find the Textbox wrong way which gioven error as you told
Try to Run this code its working with your current selected index in repeter's dropdown items..

protected void ddldept_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList d = (DropDownList)sender;
//TextBox t = (TextBox)sender;

int Value = Convert.ToInt32(d.SelectedValue);
int index = d.TabIndex;
if (Value == 2)
{
TextBox tb = (TextBox)Repeater1.Items[index].FindControl("txtdriver");
tb.Text = "N/a";
TextBox tbl = (TextBox)Repeater1.Items[index].FindControl("txtlocation");
tbl.Text = "Yard";
}
// Use d here
}
 
Share this answer
 
protected void ddldept_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList d= (DropDownList)sender;
int currentItemIndex = ((RepeaterItem)d.NamingContainer).ItemIndex;
Label lbloriginalvalue =(Label)rptAgentFields.Items[currentItemIndex].FindControl("lbloriginalvalue");
string value = d.SelectedValue;
}
 
Share this answer
 
Comments
TheRealSteveJudge 8-May-20 8:56am    
The question is over 6 years old.
I hope the OP is still alive.

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