将Vs 2010与C#结合使用,并使用更多列绑定gridview。列包含Child 控件,子控件是Dropdown list.Am在某些条件下使用RowDataBound事件。因此gridview加载时间正在扩展。可以减少gridview的加载时间。
这是我的aspx
<asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="false" CssClass="normtxt"
HeaderStyle-BackColor="#819FF7" HeaderStyle-Font-Bold="true" EmptyDataText="No records found"
OnRowCancelingEdit="gvDetails_RowCancelingEdit" HeaderStyle-Height="30px"
OnRowDeleting="gvDetails_RowDeleting" OnRowDataBound="gvDetails_RowDataBound"
OnRowEditing="gvDetails_RowEditing" OnRowUpdating="gvDetails_RowUpdating" OnRowCommand="gvDetails_RowCommand">
<RowStyle ForeColor="#000066" />
<HeaderStyle BackColor="#7BA1C3" Font-Bold="false" ForeColor="White" />
<Columns>
<%-- <asp:TemplateField ItemStyle-Width="40px">
<HeaderTemplate>
<asp:CheckBox ID="chkAll" runat="server" Text="All" AutoPostBack="true"
OnCheckedChanged="chkAll_OnCheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkOne" runat="server" AutoPostBack="true" OnCheckedChanged="chkAll_OnCheckedChanged" />
</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="ParagraphStyle" ItemStyle-Width="150" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblParagraphStyle" runat="server" Text='<%#Eval("ParagraphStyle") %>' />
<%-- <asp:TextBox ID="txtParagraphStyle" runat="server" Text='<%# Eval("ParagraphStyle") %>'
Visible="false" ></asp:TextBox>--%>
<%-- <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" ServiceMethod="AutoCompleteAjaxParaRequest"
ServicePath="Service1.asmx" MinimumPrefixLength="1" CompletionInterval="100"
EnableCaching="false" CompletionSetCount="10" TargetControlID="txtParagraphStyle"
FirstRowSelected="true" ShowOnlyCurrentWordInCompletionListItem="true">
</asp:AutoCompleteExtender>--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Parent" ItemStyle-Width="150" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblParent" runat="server" Text='<%# Eval("Parent") %>'></asp:Label>
<%-- <asp:TextBox ID="txtParent" runat="server" Text='<%#Eval("Parent") %>' Visible="false" />--%>
<%--<asp:AutoCompleteExtender ID="AutoCompleteExtender2" runat="server" ServiceMethod="AutoCompleteAjaxParentRequest"
ServicePath="Service1.asmx" MinimumPrefixLength="1" CompletionInterval="100"
EnableCaching="false" CompletionSetCount="10" TargetControlID="txtParent" FirstRowSelected="true"
ShowOnlyCurrentWordInCompletionListItem="true">
</asp:AutoCompleteExtender>--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="fnCriteria" ItemStyle-Width="150" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:DropDownList ID="ddlfnCriteria" runat="server" Width="150px" AutoPostBack="true" class="chzn-select" onselectedindexchanged="DropDownList1_SelectedIndexChanged" />
<asp:HiddenField ID="hdnfncriteria" runat="server" Value='<%#Eval("fncriteria") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="fnCase" ItemStyle-Width="10" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:DropDownList ID="ddlfnCase" runat="server" Width="150px" AutoPostBack="true" class="chzn-select" onselectedindexchanged="DropDownList1_SelectedIndexChanged" >
</asp:DropDownList>
<asp:HiddenField ID="hdnfncase" runat="server" Value='<%#Eval("fnCase") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="fnFormat" ItemStyle-Width="150" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:DropDownList ID="ddlfnFormat" runat="server" Width="150px" AutoPostBack="true" class="chzn-select" onselectedindexchanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
<asp:HiddenField ID="hdnfnFormat" runat="server" Value='<%#Eval("fnFormat") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="fnDelete" ItemStyle-Width="150" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:DropDownList ID="ddlfnDelete" runat="server" Width="150px" AutoPostBack="true" class="chzn-select" onselectedindexchanged="DropDownList1_SelectedIndexChanged" >
</asp:DropDownList>
<asp:HiddenField ID="hdnfnDelete" runat="server" Value='<%#Eval("fnDelete") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="fnInsert" ItemStyle-Width="150" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:DropDownList ID="ddlfnInsert" runat="server" Width="150px" AutoPostBack="true" class="chzn-select" onselectedindexchanged="DropDownList1_SelectedIndexChanged" >
</asp:DropDownList>
<asp:HiddenField ID="hdnfnInsert" runat="server" Value='<%#Eval("fnInsert") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="fnTruncate" ItemStyle-Width="150" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblfnTruncate" runat="server" Text='<%# Eval("fnTruncate") %>'></asp:Label>
<asp:TextBox ID="txtfnTruncate" runat="server" Text='<%#Eval("fnTruncate") %>' Visible="false" />
<asp:AutoCompleteExtender ID="AutoCompleteExtender8" runat="server" ServiceMethod="AutoCompleteAjaxfnTruncateRequest"
ServicePath="Service1.asmx" MinimumPrefixLength="1" CompletionInterval="100"
EnableCaching="false" CompletionSetCount="10" TargetControlID="txtfnTruncate"
FirstRowSelected="true" ShowOnlyCurrentWordInCompletionListItem="true">
</asp:AutoCompleteExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="fnOrder" ItemStyle-Width="150" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblfnOrder" runat="server" Text='<%# Eval("fnOrder") %>'></asp:Label>
<asp:TextBox ID="txtfnOrder" runat="server" Text='<%#Eval("fnOrder") %>' Visible="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Execution_Order" ItemStyle-Width="150" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblExecution_Order" runat="server" Text='<%# Eval("Execution_Order") %>'></asp:Label>
<asp:TextBox ID="txtExecution_Order" runat="server" Text='<%#Eval("Execution_Order") %>' Visible="false" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我背后的代码是
protected void gvDetails_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
try
{
//Find the DropDownList in the Row
DropDownList ddlfncriteria = (e.Row.FindControl("ddlfnCriteria") as DropDownList);
HiddenField hdnfncriteria = (e.Row.FindControl("hdnfncriteria") as HiddenField);
HiddenField hdnfncase = (e.Row.FindControl("hdnfncase") as HiddenField);
DropDownList ddlfnCase = (e.Row.FindControl("ddlfnCase") as DropDownList);
DropDownList ddlfnFormat = (e.Row.FindControl("ddlfnFormat") as DropDownList);
HiddenField hdnfnFormat = (e.Row.FindControl("hdnfnFormat") as HiddenField);
DropDownList ddlfnDelete = (e.Row.FindControl("ddlfnDelete") as DropDownList);
HiddenField hdnfnDelete = (e.Row.FindControl("hdnfnDelete") as HiddenField);
DropDownList ddlfnInsert = (e.Row.FindControl("ddlfnInsert") as DropDownList);
HiddenField hdnfnInsert = (e.Row.FindControl("hdnfnInsert") as HiddenField);
ddlfncriteria.DataSource = clsCommon.ExecuteQuery("select '--Select--' as fnCriteria union select distinct fnCriteria from customizeFunction_test_from_frontend where fnCriteria <> '' ", "fncrt");
ddlfncriteria.DataTextField = "fnCriteria";
ddlfncriteria.DataValueField = "fnCriteria";
if (hdnfncriteria.Value != "")
{
ddlfncriteria.SelectedValue = hdnfncriteria.Value;
}
else
{
ddlfncriteria.SelectedIndex = 0;
}
ddlfncriteria.DataBind();
List<string> dd2 = new List<string>();
dd2.Add("--Select--");
dd2.Add("Lower case");
dd2.Add("Upper case");
dd2.Add("Title case");
dd2.Add("Sentence case");
ddlfnCase.DataSource = dd2;
if (hdnfncase.Value == "0")
{
ddlfnCase.SelectedIndex = 1;
}
else if (hdnfncase.Value == "1")
{
ddlfnCase.SelectedIndex = 2;
}
else if (hdnfncase.Value == "2")
{
ddlfnCase.SelectedIndex = 3;
}
else if (hdnfncase.Value == "4")
{
ddlfnCase.SelectedIndex = 5;
}
ddlfnCase.DataBind();
ddlfnFormat.DataSource = clsCommon.ExecuteQuery(" select '--Select--' as fnFormat union select distinct fnFormat from customizeFunction_test_from_frontend where fnFormat <> '' ", "fnformt");
ddlfnFormat.DataTextField = "fnFormat";
ddlfnFormat.DataValueField = "fnFormat";
if (hdnfnFormat.Value != "")
{
ddlfnFormat.SelectedValue = hdnfnFormat.Value;
}
else
{
ddlfnFormat.SelectedIndex = 0;
}
ddlfnFormat.DataBind();
ddlfnDelete.DataSource = clsCommon.ExecuteQuery(" select '--Select--' as fnDelete union all select distinct fnDelete from customizeFunction_test_from_frontend where fnDelete <> '' ", "fnformt");
ddlfnDelete.DataTextField = "fnDelete";
ddlfnDelete.DataValueField = "fnDelete";
if (hdnfnDelete.Value != "")
{
ddlfnDelete.SelectedValue = hdnfnDelete.Value;
}
else
{
ddlfnDelete.SelectedIndex = 0;
}
ddlfnDelete.DataBind();
ddlfnInsert.DataSource = clsCommon.ExecuteQuery(" select '--Select--' as fnInsert union all select distinct fnInsert from customizeFunction_test_from_frontend where fnInsert <> '' ", "fnformt");
ddlfnInsert.DataTextField = "fnInsert";
ddlfnInsert.DataValueField = "fnInsert";
if (hdnfnInsert.Value != "")
{
ddlfnInsert.SelectedValue = hdnfnInsert.Value;
}
else
{
ddlfnInsert.SelectedIndex = 0;
}
ddlfnInsert.DataBind();
//ddlfncriteria.DataSource = dd2;
//ddlfncriteria.DataBind();
//Add Default Item in the DropDownList
//ddlfncriteria.Items.Insert(0, new ListItem("Please select"));
//Select the Country of Customer in DropDownList
// string country = (e.Row.FindControl("lblCountry") as Label).Text;
// ddlfncriteria.Items.FindByValue(country).Selected = true;
}
catch (Exception ex)
{
}
}
}
建议我找到解决方案。