asp.net page design
<asp:GridView ID="gvPatient" runat="server" AutoGenerateColumns="False" AllowSorting="True"
DataKeyNames="AN" CssClass="tablestyle" AllowPaging="True" OnSorting="gvPatient_Sorting"
OnDataBound="gvPatient_DataBound" OnRowDataBound="gvPatient_RowDataBound"
OnRowCreated="gvPatient_RowCreated" PageSize="25" Style="table-layout: fixed;"
Width="100%">
<AlternatingRowStyle CssClass="altrowstyle" />
<HeaderStyle CssClass="headerstyle" />
<RowStyle CssClass="rowstyle" Wrap="true" />
<EmptyDataRowStyle BackColor="#edf5ff" Height="300px" VerticalAlign="Middle" HorizontalAlign="Center" />
<EmptyDataTemplate>
No Records Found
</EmptyDataTemplate>
<Columns>
<asp:TemplateField HeaderText="Diagnosis">
<ItemTemplate>
<asp:TextBox ID="txtDiagnosis" runat="server" Width="87%" MaxLength="200" Text='<%#Eval("Diagnosis") %>' Height="30px" TextMode="MultiLine" Style="resize: none;"></asp:TextBox>
<asp:ImageButton ID="ibtnSave" runat="server" ImageUrl="~/images/SaveSmall.png" ToolTip="Save Diag" onclick="ibtnSave_Click" ImageAlign="NotSet" />
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" MinimumPrefixLength="1"
ServiceMethod="GetVendorList" TargetControlID="txtDiagnosis" UseContextKey="True"
CompletionListCssClass="autocomplete_completionListElement" CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
CompletionListItemCssClass="autocomplete_listItem" DelimiterCharacters=";, :"
ShowOnlyCurrentWordInCompletionListItem="True" CompletionInterval="1000"
CompletionSetCount="10" />
</ItemTemplate>
<ItemStyle VerticalAlign="Middle" />
</asp:TemplateField>
</Columns>
</asp:GridView>
code behide :
using AjaxControlToolkit;
protected void gvPatient_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//config AutoCompleteExtender in gridview
//find textbox
TextBox txtDiagnosis = (TextBox)e.Row.FindControl("txtDiagnosis");
//find autocomplete extender
AutoCompleteExtender AutoComplete1 = (AutoCompleteExtender)e.Row.FindControl("AutoCompleteExtender1");
//set target control id of autocomplete extender
AutoComplete1.TargetControlID = txtDiagnosis.ID;
}
}
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetVendorList(string prefixText, int count, string contextKey)
{
SqlConnection con = new SqlConnection(dbClass.NAVTestDBConn);
con.Open();
string sql = string.Format("SELECT top {0} '['+V.NO_+'] ('+V.[Search Name]+') '+V.Name " +
"FROM [Phuket International Hospital$Vendor] AS V " +
"WHERE V.Name like @prefixText or [Search Name] like @prefixText or V.NO_ like @prefixText " +
"ORDER BY V.Name ASC ", count);
SqlDataAdapter da = new SqlDataAdapter(sql, con);
da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = "%" + prefixText + "%";
DataTable dt = new DataTable();
da.Fill(dt);
string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr[0].ToString(), i);
i++;
}
return items;
}
No comments:
Post a Comment