Gridview中静态下拉列表的DataBind不起作用



我用网格把一个屏幕装进了板条箱。网格包含一个下拉列表以及一些文本框字段。它们都是从同一张桌子上取的。我可以在dropdownlist中选择一个值,它可以正确地更新数据库。但一旦更新,它就不会在屏幕上正确显示。它显示下拉列表中的第一个项目。文本框会正确反映,但不会下拉。我错过了什么?将数据绑定到网格中的下拉列表时出现问题。

<%@ Register Assembly="obout_ComboBox" Namespace="Obout.ComboBox" TagPrefix="cc2" %>
<%@ Register Assembly="obout_Grid_NET" Namespace="Obout.Grid" TagPrefix="cc1" %>
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">               
<div class="x_content">
<div>
<cc1:Grid ID="Grid1" runat="server" AllowAddingRecords="true" CallbackMode="true" Serialize="true" 
EnableRecordHover="true" FolderStyle="Styles/style_13" AllowPaging="false" 
AllowPageSizeSelection="false"  AutoGenerateColumns="false" 
Width= "100%" OnInsertCommand="InsertRecord" 
OnDeleteCommand="DeleteRecord" OnUpdateCommand="UpdateRecord"  > 
<ClientSideEvents OnClientCallbackError="onCallbackError" />

<Columns>       
<cc1:Column HeaderText="ASNNumber" DataField="ReturnASNKey" Visible="false"                     ReadOnly="true" Width="30" ></cc1:Column>
<cc1:Column  HeaderText="LineNo" DataField="RLineNo" Width="45" ReadOnly="true" > </cc1:Column> 
<cc1:Column  HeaderText="Bu" DataField="Bu"   Width="150">
<TemplateSettings TemplateId="BuTemplate"  EditTemplateId="BuTemplate" />
</cc1:Column>
//More Columns Present
</Columns>
<Templates>
<cc1:GridTemplate runat="server" ID="BuTemplate" ControlID="ddBu" >
<Template>
<asp:DropDownList ID="ddBu" runat="server"   >
<asp:ListItem Text="CS" Value="CS"></asp:ListItem>
<asp:ListItem Text="CT" Value="CT"></asp:ListItem>
<asp:ListItem Text="DS" Value="DS"></asp:ListItem>
</asp:DropDownList>
</Template>
</cc1:GridTemplate>    
</Templates>         
</cc1:Grid>
</div>
</div>
</div>
</div>
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//other unrelated function calls
}
populateInbound_detail();
}
protected void InsertRecord(object sender, GridRecordEventArgs e)
{
// code to update the values in database
populateInbound_detail();
}
private void populateInbound_detail()
{
DataTable table = new DataTable();
// get the connection
connection.Open();
// write the sql statement to execute
string sql = "SELECT * FROM [T1] where ReturnASNKey = '" + txtReturnASNKey.Text + "'   order by RLineNo ASC ";
// instantiate the command object to fire
using (SqlCommand cmd = new SqlCommand(sql, connection))
{
// get the adapter object and attach the command object to i
using (SqlDataAdapter ad = new SqlDataAdapter(cmd))
{
ad.Fill(table);
}
}
connection.Close();
// specify the data source for the GridView
Grid1.DataSource = table;
// bind the data now
Grid1.DataBind();
}

能够使其工作。我的错误是<TemplateSettings TemplateId="BuTemplate" EditTemplateId="BuTemplate" />

应该是<TemplateSettings EditTemplateId="BuTemplate" />TemplateID的添加不允许在屏幕上显示存储的值。

最新更新