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

时间:2013-08-01 05:19:58

标签: c# javascript jquery asp.net

我有gridview文本框列, 我需要在gridview中自动填充文本框...

我的代码是,

<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

1 个答案:

答案 0 :(得分:0)

<input type="text" values="<%# Eval('txtMedName')%>'">