如何在asp.net中的repeater中填充selectedindexchanged上的文本框 [英] how to fill textbox on selectedindexchanged in repeater in asp.net

查看:75
本文介绍了如何在asp.net中的repeater中填充selectedindexchanged上的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个转发器,

我有一个下拉列表n文本框。



onselectedindexchanged ddl的事件,我想填写特定的文本框。



可能正在使用clientid或者其他....



plz建议我;



ASP代码:

< asp:Repeater ID =Repeater1runat =server
onitemdatabound =Repeater1_ItemDataBound>
< HeaderTemplate>
< table class =table table-striped table-borderedid =a0>
< thead>
< tr>
< th> DoorNo#< / th>
< th> PlateNo#< / th>
< th>状态< / th>
< th>驱动程序< / th>
< th>部门< / th>
< th>位置< / th>
< / tr>
< / thead>
< tbody>
< / HeaderTemplate>
< ItemTemplate>
< tr class =odd gradeX>
< td>
< asp:Label ID =lbldoornorunat =serverText ='<%#Eval(DoorNo)%>'>< / asp:Label>< / td>
< td>< asp:Label ID =lblplatenorunat =serverText ='<%#Eval(PlateNo)%>'>< / asp:Label>< ; / TD>
< td>< asp:DropDownList ID =ddlstatusOnSelectedIndexChanged =ddldept_SelectedIndexChanged
AutoPostBack =trueWidth =100pxrunat =server>
< asp:ListItem Value =1>活动< / asp:ListItem>
< asp:ListItem Value =2>不活动LT; / ASP:的ListItem>
< / asp:DropDownList>< / td>
< td>< asp:TextBox ID =txtdriverrunat =serverText =a>< / asp:TextBox>< / td>
< td>
< asp:UpdatePanel ID =UpdatePanel1runat =serverUpdateMode =Conditional>
< ContentTemplate>
< asp:DropDownList ID =ddldeptrunat =server>
< / asp:DropDownList>
< / ContentTemplate>
<触发器>
< asp:PostBackTrigger ControlID =ddldept/>
<% - < asp:PostBackTrigger ControlID =ddldept/> - %>
< /触发器>
< / asp:UpdatePanel>
< / td>
< td>< asp:TextBox ID =txtlocationText =yardrunat =server>< / asp:TextBox>< / td>

< / tr>
< / ItemTemplate>
< FooterTemplate>
< table width =100%>
< tbody>< tr>< td align =center>< br />
< asp:Button ID =btnCnclrunat =serverText =CancelCssClass =btn btn-danger btn-smallFont-Bold =Trueonclick =ButtonCncl_Click/>
 
< asp:Button ID =btnSaverunat =serverCssClass =btn btn-success btn-smallText =SaveFont-Bold =Trueonclick =ButtonSave_Click/> < / TD>< / TR>< / tbody的>
< / table>
< / FooterTemplate>
< / asp:Repeater>





我的代码:



 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)为TextBox;
tbl.Textt =Yard;
}
//在这里使用d
}





plz帮帮我.... ..





谢谢

解决方案

亲爱的Subhan,


中继器控件用于显示网格或列表等重复数据模式



例如:

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







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



我不确定你想通过添加一个文本框来实现什么目标,我建议创建项目模板,然后将数据绑定到那些项目模板。



希望这有帮助



问候

Omer。


  protected   void  ddldept_SelectedIndexChanged( object  sender,Even tArgs 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;
}
}
}


你发现文本框错误的方式gioven错误你告诉

尝试在repeter的下拉项中运行此代码,使用当前选定的索引 ..



protected void ddldept_SelectedIndexChanged(object sender ,EventArgs e)

{

DropDownList d =(DropDownList)发送者;

// TextBox t =(TextBox)发送者;



int Value = Convert.ToInt32(d.SelectedValue);

int index = d.TabIndex;

if(值== 2)

{

TextBox tb =(TextBox)Repeater1.Items [index] .FindControl(txtdriver);

tb.Text =N / a;

TextBox tbl =(TextBox)Repeater1.Items [index] .FindControl(txtlocation);

tbl.Text = Yard;

}

//在这里使用

}

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

解决方案

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.


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";
                    }
        }
}


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
}


这篇关于如何在asp.net中的repeater中填充selectedindexchanged上的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆