如何在gridview中自动完成文本框

how to auto complete textbox in gridview?

本文关键字:文本 gridview      更新时间:2023-09-26

我有网格视图文本框列,我需要在grridview中自动完成文本框。。。

我的代码是

<table style="width: 700px;">
                <tr>
                    <th colspan="3">Medicine Detail :
                    </th>
                </tr>

                <tr>
                    <td colspan="3">
                        <script type="text/javascript">
                            $(function () {
                                var availableTags = [ <%= SuggestionList %>];
                                                $("#<%= txtMedName.ClientID %>").autocomplete({
                                                    source: availableTags
                                                });
                                            });
                                        </script>
                        <asp:GridView ID="Gridview1" runat="server" ShowFooter="true" AutoGenerateColumns="false" Width="700px" HorizontalAlign="Center"
                            OnRowDeleting="Gridview1_RowDeleting">
                            <Columns>
                                <asp:BoundField DataField="RowNumber" HeaderText="S.No" />
                                <asp:TemplateField HeaderText="Medicine Name">
                                    <ItemTemplate>
                                        <asp:TextBox ID="txtMedName" runat="server" CssClass="TextBox"></asp:TextBox>
                                    </ItemTemplate>
                                </asp:TemplateField> </Columns>
                        </asp:GridView>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">&nbsp;</td>
                    <td>
                        <asp:Button ID="Button7" runat="server" Text="Add" CssClass="button" OnClick="Button7_Click" />
                        <asp:Button ID="Button8" runat="server" Text="Cancel" CssClass="button" PostBackUrl="~/PatientEntry.aspx" />
                    </td>
                </tr>
            </table>

我的.cs代码是

 public string SuggestionList = ""; string queryString = "select * from NewMedicineMaster";
            using (SqlConnection con = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["HospitalConnection"].ConnectionString))
            {
                using (SqlCommand command = new SqlCommand(queryString, con))
                {
                    con.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            if (string.IsNullOrEmpty(SuggestionList))
                            {
                                SuggestionList += "'"" + reader["MedName"].ToString() + "-" + reader["MedId"].ToString() + "'"";
                            }
                            else
                            {
                                SuggestionList += ", '"" + reader["MedName"].ToString() + "-" + reader["MedId"].ToString() + "'"";
                            }
                        }
                    }
                }
            }

但是错误来了,

 The Name 'txtMedName' does not exist in the current context
<input type="text" values="<%# Eval('txtMedName')%>'">