是否有可能用数据表填充detailsview并仍使用模板字段而不显示两组数据? [英] Is it possible to fill a detailsview with a datatable and still use templated fields without showing both sets of data?
问题描述
我有一个用数据表填充的detailsview.我也有用于自定义代码的模板化字段. detailsview显示两组数据都是重复的,一组来自数据表,另一组来自模板字段.我只想显示一组数据,即模板字段.有人可以向我解释我的秘诀,并提出一种更好的方法来解决这个问题吗?
另外,由于该程序的最初设计方式,我无法使用SqlDataSources.我拥有的代码在下面,并在detailsview中进行了缩短,以使其更易于阅读.
I have a detailsview that I am populating with a datatable. I also have templated fields for custom code. The detailsview shows both sets of data which are duplicates, one set from the datatable and the other set from the templated fields. I only want to display one set of the data, that being the templated fields. Can someone explain to me my falacies and suggest a better way to handle this please?
Also, I cannot use SqlDataSources due to the way this program was originally designed. The code I have is below and shortened in the detailsview to make it easier to read.
<asp:DetailsView ID="DetailsView1" runat="server" onmodechanging="DetailsView1_ModeChanging" OnItemUpdating="DetailsView1_ItemUpdating"
DefaultMode="Edit" CssClass="panelStyle" OnDataBound="DetailsView1_DataBound" CausesValidation="false" GridLines="None"><%----%>
<Fields>
<asp:TemplateField HeaderText="Function Name">
<EditItemTemplate>
<asp:DropDownList ID="ddlfunctions" runat="server"
DataSource='<%# _functionCollection %>' DataTextField="Display" DataValueField="Name">
</asp:DropDownList>
<br />
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("entryFunctionName") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("entryFunctionName") %>'></asp:Label>
</ItemTemplate>
</Fields>
</asp:DetailsView>
string entryID;
DataTable dtEdit = new DataTable();
protected void gvEntries_SelectedIndexChanged(object sender, EventArgs e)
{
// Determine the index of the selected row.
int index = gvEntries.SelectedIndex;
entryID = gvEntries.DataKeys[index].Value.ToString();
string queryString = ("Select [entryFunctionName], [entrySegment], [entryLOB]," +
"[entryTime], [entryAccountNumber], [entryProgramRevOrg], [entryQuantity], " +
"[entryNotes] From tblEntries Where entryEntryID = " + entryID);
dtEdit = DDLGetData(queryString);
DetailsView1.ChangeMode(DetailsViewMode.Edit);
DetailsView1.DataSource = dtEdit;
DetailsView1.DataBind();
ModalPopupExtender1.Controls.Add(editPanel);
ModalPopupExtender1.Show();
}
推荐答案
如果只想显示模板字段,则应设置
DetailsView.AutoGenerateRows = false;
或
If you want to show only your template fields you should set
DetailsView.AutoGenerateRows = false;
or
<asp:detailsview id="DetailsView1" runat="server" autogeneraterows="false" onmodechanging="DetailsView1_ModeChanging" onitemupdating="DetailsView1_ItemUpdating" defaultmode="Edit" cssclass="panelStyle" ondatabound="DetailsView1_DataBound" causesvalidation="false" gridlines="None" xmlns:asp="#unknown">
</asp:detailsview>
这篇关于是否有可能用数据表填充detailsview并仍使用模板字段而不显示两组数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!