0

我有 gridview 文本框列,我需要在 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
4

1 回答 1

0
<input type="text" values="<%# Eval('txtMedName')%>'">
于 2013-08-01T05:31:36.213 回答