如何将AutocompleteExtender用于数据网格中的文本框 [英] How to use AutocompleteExtender for a textbox in a datagrid

查看:66
本文介绍了如何将AutocompleteExtender用于数据网格中的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想将autocompleteExtender实现到datagrid.i里面的文本框中,为此编写了web服务。

 <  <%@    注册   汇编  =  AjaxControlToolkit   命名空间  =  AjaxControlToolkit   < span class =code-attribute> TagPrefix   =  smartsearch   %>  
asp:DataGrid ID = dgProductList样式= overflow:auto runat = server AllowPaging = True
BorderWidth = 0 CssClass = < span class =code-string> gridbody CellSpacing = 1 AutoGenerateColumns = False
PageSize = 5 CellPadding = 0 >
< ItemStyle CssClass = GridText > < / ItemStyle >
< HeaderStyle CssClass = Gridheader > < / HeaderStyle >
< Columns>
< asp:BoundColumn DataField = mio_id Visible = False > < / asp:BoundColumn >
<% - < asp:BoundColumn DataField = Entity_ID可见= False > < / asp:BoundColumn > - % >
< asp:Bou ndColumn DataField = mio_category可见= False > < / asp:BoundColumn >
< asp:TemplateColumn HeaderStyle-VerticalAlign = 中间 >
< HeaderTemplate> ;
< input type = 复选框 id = chkProductsListDeleteAll runat = server name = chkTraceabilityDeleteAll > ;
< / HeaderTemplate >
< ItemTemplate>
< input type = 复选框 id = chkProductsListDelete runat = server name = chkTraceabilityDelete > ;
< / ItemTemplate >
< / asp:TemplateColumn >
< asp:ButtonColumn HeaderTex t = ButtonType = < span class =code-string> LinkBut​​ton Text = < img src ='.. /../images/Edit.gif'border = 0 />
CommandName = 更新 />


< asp:TemplateColumn>
< HeaderStyle Horizo​​ntalAlign = 中心 />
< HeaderTemplate>
类别< / HeaderTemplate >
< ItemTemplate>
< asp:DropDownList Width = 350px CssClass = 下拉列表 ID = drpCategory runat = server >
< / asp:DropDownList >
< / ItemTemplate >
< / asp:TemplateColumn >

< asp:TemplateColumn>
< HeaderStyle Horizo​​ntalAlign = 中心 />
< HeaderTemplate>
产品< / HeaderTemplate >
< ItemTemplate>
< asp:TextBox ID = TxtProducts runat = server Text = ' <%#DataBinder.Eval(Container.DataItem,mio_product)%>' AutoPostBack = true > < / asp:TextBox >

< smartsearch:AutoCompleteExtender BehaviorID = AutoCompleteEx1 ID = p roductTextBox runat = server
UseContextKey = true已启用= true TargetControlID = TxtProducts MinimumPrefixLength = 1
EnableCaching = true ServiceMethod = GetProducts ServicePath = GetDataForSmartSearch.asmx CompletionInterval = 1000
CompletionSetCount = 20 CompletionListItemCssClass = AutoCompleteExtender_CompletionListItem
CompletionListHighlightedItemCssClass = AutoCompleteExtender_HighlightedItem
CompletionListCssClass = AutoCompleteExtender_CompletionList DelimiterCharacters = ;,: >

< ;动画和GT;
< OnShow>
<序列>
< OpacityAction Opacity = 0 />
< HideAction Visible = true />
< ScriptAction Script =
//缓存大小并设置初始大小
var behavior = $ find('AutoCompleteEx1');
if(!behavior._height){
var target = behavior.get_completionList();
behavior._height = target.offsetHeight - 2;
target.style.height ='0px';
}
/>

< Parallel Duration = 。4 >
< FadeIn />
< Length PropertyKey = height StartValue = 0 EndValueScript = $ find('AutoCompleteEx1')._ height />
< / 并行 >
< / 序列 >
< / OnShow >
< OnHide>
<% - 折扣为0px并淡出 out - %>
< Parallel Duration = 。4 >
< FadeOut />
< Length PropertyKey = height StartValueScript = $ find('AutoCompleteEx1')._ height EndValue = 0 />
< / 并行 >
< / OnHide >
< / 动画 >
< / smartsearch:AutoCompleteExtender >

<% - < input type = text style = width:350px;önclick= GetPromt(this); id = TxtProducts
class = textbox name = TxtProducts runat = server value = ' <%#DataBinder.Eval(Container.DataItem,mio_product)%>'> - %>
< / ItemTemplate >
< / asp:TemplateColumn > < / >
< PagerStyle Visible = False > < / PagerStyle >
< / asp:DataGrid >
< / div >










在添加新行按钮时,它会发出此错误 -

Microsoft JScript运行时错误:Sys.InvalidOperationException:具有相同IDAutoCompleteEx1的两个组件无法添加到应用程序中。



我想使用Ajax AutoCompleteExtender进入DataGrid中的文本框



Webservice代码----------------



[WebService(Namespace =http://tempuri.org/)]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

//要允许使用ASP.NET AJAX从脚本调用此Web Service,请取消注释以下行。

[System.Web.Script.Services.ScriptService]

公共类GetDataForSmartSearch:System.Web.Services.WebService

{



public GetDataForSmartSearch()

{



//如果使用,请取消注释以下行设计组件

// InitializeComponent();

}



[WebMethod]

[System.Web.Script.Services.ScriptMethod()] < br $>
// [System.Web.Services.WebMethod]



public string [] GetProducts(string PrefixTextForProducts,int count)

{

CController objGetProducts = new CController();

DataSet ds1 = new DataSet();

int i;

ds1 = objGetProducts.GetProductsData(PrefixTextForProducts);

列表str =新列表(ds1.Tables [0] .Rows.Count);

/ / DataRow [] dr = ds

if(ds1.Tables [0] .Rows.Count> 0)

{

for( i = 0; i< ds1.Tables [0] .Rows.Count; i ++)

{

str.Add(ds1.Tables [0] .Rows [ i] [mio_product]。ToString());

}

}

返回str.ToArray();



}

决方案
找到( 'AutoCompleteEx1');
if(!behavior._height){
var target = behavior.get_completionList();
behavior._height = target.offsetHeight - 2;
target.style.height ='0px';
} />

< Parallel Duration = .4 >
< FadeIn />
< Length PropertyKey = height StartValue = 0 EndValueScript =


find('AutoCompleteEx1' )._ height />
< / 并行 >
< / 序列 < span class =code-keywor d>>
< / OnShow >
< OnHide>
<% - 折扣为0px并淡出 out - %>
< Parallel Duration = 。4 >
< FadeOut />
< Length PropertyKey = height StartValueScript =


find('AutoCompleteEx1')._ height EndValue = 0 />
< / 并行 >
< / OnHide >
< / 动画 >
< / smartsearch:AutoCompleteExtender >

<% - < input type = text style = width:350px;önclick= GetPromt(this); id = TxtProducts
class = textbox name = TxtProducts runat = server value = ' <%#DataBinder.Eval(Container.DataItem,mio_product)%>'> - %>
< / ItemTemplate >
< / asp:TemplateColumn > < / >
< PagerStyle Visible = False > < / PagerStyle >
< / asp:DataGrid >
< / div >










在添加新行按钮时,它会发出此错误 -

Microsoft JScript运行时错误:Sys.InvalidOperationException:具有相同IDAutoCompleteEx1的两个组件无法添加到应用程序中。



我想使用Ajax AutoCompleteExtender进入DataGrid中的文本框



Webservice代码----------------



[WebService(Namespace =http://tempuri.org/)]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

//要允许使用ASP.NET AJAX从脚本调用此Web Service,请取消注释以下行。

[System.Web.Script.Services.ScriptService]

公共类GetDataForSmartSearch:System.Web.Services.WebService

{



public GetDataForSmartSearch()

{



//如果使用,请取消注释以下行设计组件

// InitializeComponent();

}



[WebMethod]

[System.Web.Script.Services.ScriptMethod()] < br $>
// [System.Web.Services.WebMethod]



public string [] GetProducts(string PrefixTextForProducts,int count)

{

CController objGetProducts = new CController();

DataSet ds1 = new DataSet();

int i;

ds1 = objGetProducts.GetProductsData(PrefixTextForProducts);

列表str =新列表(ds1.Tables [0] .Rows.Count);

/ / DataRow [] dr = ds

if(ds1.Tables [0] .Rows.Count> 0)

{

for( i = 0; i< ds1.Tables [0] .Rows.Count; i ++)

{

str.Add(ds1.Tables [0] .Rows [ i] [mio_product]。ToString());

}

}

返回str.ToArray();



}


Hi,
I want to implement AutocompleteExtender into the textbox which is inside the datagrid.i have written webservice for that.

<<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="smartsearch" %>
asp:DataGrid ID="dgProductList" Style="overflow: auto" runat="server" AllowPaging="True"
                                                                BorderWidth="0" CssClass="gridbody" CellSpacing="1" AutoGenerateColumns="False"
                                                                PageSize="5" CellPadding="0">
                                                                <ItemStyle CssClass="GridText"></ItemStyle>
                                                                <HeaderStyle CssClass="Gridheader"></HeaderStyle>
                                                                <Columns>
                                                                    <asp:BoundColumn DataField="mio_id" Visible="False"></asp:BoundColumn>
                                                                   <%-- <asp:BoundColumn DataField="Entity_ID" Visible="False"></asp:BoundColumn>--%>
                                                                   <asp:BoundColumn DataField="mio_category" Visible="False"></asp:BoundColumn>
                                                                    <asp:TemplateColumn HeaderStyle-VerticalAlign="Middle">
                                                                        <HeaderTemplate>
                                                                            <input type="checkbox" id="chkProductsListDeleteAll"  runat="server" name="chkTraceabilityDeleteAll">
                                                                        </HeaderTemplate>
                                                                        <ItemTemplate>
                                                                            <input type="checkbox" id="chkProductsListDelete"  runat="server" name="chkTraceabilityDelete">
                                                                        </ItemTemplate>
                                                                    </asp:TemplateColumn>
                                                                    <asp:ButtonColumn HeaderText="" ButtonType="LinkButton" Text="<img src='../../images/Edit.gif'  border=0/>"
                                                                        CommandName="Update" />
                                                                    
                                                                   
                                                                    <asp:TemplateColumn>
                                                                    <HeaderStyle HorizontalAlign="Center" />
                                                                        <HeaderTemplate>
                                                                            Category</HeaderTemplate>
                                                                        <ItemTemplate>
                                                                            <asp:DropDownList Width="350px" CssClass="dropdown" ID="drpCategory" runat="server">
                                                                            </asp:DropDownList>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateColumn>
                                                                   
                                                                    <asp:TemplateColumn>
                                                                     <HeaderStyle HorizontalAlign="Center" />
                                                                        <HeaderTemplate>
                                                                            Products</HeaderTemplate>
                                                                        <ItemTemplate>
                                                                         <asp:TextBox ID="TxtProducts" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"mio_product")%>' AutoPostBack="true"  ></asp:TextBox>
                                                                         
                                                                         <smartsearch:AutoCompleteExtender  BehaviorID="AutoCompleteEx1" ID="productTextBox"  runat="server"
                                                            UseContextKey="true" Enabled="true" TargetControlID="TxtProducts" MinimumPrefixLength="1"
                                                            EnableCaching="true" ServiceMethod="GetProducts"  ServicePath="GetDataForSmartSearch.asmx" CompletionInterval="1000"
                                                            CompletionSetCount="20"   CompletionListItemCssClass="AutoCompleteExtender_CompletionListItem"                                                          
                                                            CompletionListHighlightedItemCssClass="AutoCompleteExtender_HighlightedItem" 
                                                            CompletionListCssClass="AutoCompleteExtender_CompletionList" DelimiterCharacters=";, :">
                                                            
                                                            <Animations>
                                                         <OnShow>
                                                   <Sequence>
                                               <OpacityAction Opacity="0" />
                                          <HideAction Visible="true" />   
                                    <ScriptAction Script="
                                         // Cache the size and setup the initial size
                                        var behavior = $find('AutoCompleteEx1');
                                        if (!behavior._height) {
                                           var target = behavior.get_completionList();
                                         behavior._height = target.offsetHeight - 2;
                                           target.style.height = '0px';
                                           }" />
                                
                                        <Parallel Duration=".4">
                                       <FadeIn />
                                <Length PropertyKey="height" StartValue="0" EndValueScript="$find('AutoCompleteEx1')._height" />
                            </Parallel>       
            </Sequence>      
          </OnShow>
      <OnHide>
         <%-- Collapse down to 0px and fade out --%>
                       <Parallel Duration=".4">
                            <FadeOut />
                            <Length PropertyKey="height" StartValueScript="$find('AutoCompleteEx1')._height" EndValue="0" />
                        </Parallel>
      </OnHide>
                                                            </Animations>
                                                        </smartsearch:AutoCompleteExtender>

                                                                            <%--<input type="text" style="width: 350px;"  önclick="GetPromt(this);" id="TxtProducts"
                                                                                class="textbox" name="TxtProducts"  runat="server" value='<%#DataBinder.Eval(Container.DataItem,"mio_product")%>'>--%>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateColumn></Columns>
                                                                <PagerStyle Visible="False"></PagerStyle>
                                                            </asp:DataGrid>
                                                        </div>






While clciking on Add New row button, its giving this error--
Microsoft JScript runtime error: Sys.InvalidOperationException: Two components with the same id 'AutoCompleteEx1' can't be added to the application.

I want to use Ajax AutoCompleteExtender into the textbox which is in DataGrid

Webservice Code----------------

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class GetDataForSmartSearch : System.Web.Services.WebService
{

public GetDataForSmartSearch()
{

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
[System.Web.Script.Services.ScriptMethod()]
// [System.Web.Services.WebMethod]

public string[] GetProducts(string PrefixTextForProducts, int count)
{
CController objGetProducts = new CController();
DataSet ds1 = new DataSet();
int i;
ds1 = objGetProducts.GetProductsData(PrefixTextForProducts);
List str = new List(ds1.Tables[0].Rows.Count);
//DataRow[] dr = ds
if (ds1.Tables[0].Rows.Count > 0)
{
for (i = 0; i < ds1.Tables[0].Rows.Count; i++)
{
str.Add(ds1.Tables[0].Rows[i]["mio_product"].ToString());
}
}
return str.ToArray();

}

解决方案

find('AutoCompleteEx1'); if (!behavior._height) { var target = behavior.get_completionList(); behavior._height = target.offsetHeight - 2; target.style.height = '0px'; }" /> <Parallel Duration=".4"> <FadeIn /> <Length PropertyKey="height" StartValue="0" EndValueScript="


find('AutoCompleteEx1')._height" /> </Parallel> </Sequence> </OnShow> <OnHide> <%-- Collapse down to 0px and fade out --%> <Parallel Duration=".4"> <FadeOut /> <Length PropertyKey="height" StartValueScript="


find('AutoCompleteEx1')._height" EndValue="0" /> </Parallel> </OnHide> </Animations> </smartsearch:AutoCompleteExtender> <%--<input type="text" style="width: 350px;" önclick="GetPromt(this);" id="TxtProducts" class="textbox" name="TxtProducts" runat="server" value='<%#DataBinder.Eval(Container.DataItem,"mio_product")%>'>--%> </ItemTemplate> </asp:TemplateColumn></Columns> <PagerStyle Visible="False"></PagerStyle> </asp:DataGrid> </div>






While clciking on Add New row button, its giving this error--
Microsoft JScript runtime error: Sys.InvalidOperationException: Two components with the same id 'AutoCompleteEx1' can't be added to the application.

I want to use Ajax AutoCompleteExtender into the textbox which is in DataGrid

Webservice Code----------------

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class GetDataForSmartSearch : System.Web.Services.WebService
{

public GetDataForSmartSearch()
{

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
[System.Web.Script.Services.ScriptMethod()]
// [System.Web.Services.WebMethod]

public string[] GetProducts(string PrefixTextForProducts, int count)
{
CController objGetProducts = new CController();
DataSet ds1 = new DataSet();
int i;
ds1 = objGetProducts.GetProductsData(PrefixTextForProducts);
List str = new List(ds1.Tables[0].Rows.Count);
//DataRow[] dr = ds
if (ds1.Tables[0].Rows.Count > 0)
{
for (i = 0; i < ds1.Tables[0].Rows.Count; i++)
{
str.Add(ds1.Tables[0].Rows[i]["mio_product"].ToString());
}
}
return str.ToArray();

}


这篇关于如何将AutocompleteExtender用于数据网格中的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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