2013-08-01 2 views
0

У меня есть GridView TextBox columnns, мне нужно автоматическое заполнение текстового поля в grridview ...Как автоматически заполнить текстовое поле в 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 

ответ

0
<input type="text" values="<%# Eval('txtMedName')%>'"> 
Смежные вопросы