I have crated a screen with a Grid. The Grid contains a dropdown along with some textbox fields. They all are fetched from same table.
I am able to select a value in dropdownlist and it updates the database correctly . But once updated , it does not display correctly back on screen. It displays the first Item in the dropdownlist. The text boxes are reflected correctly but not dropdown.
What am I missing ? Having issues with binding the data to dropdown within a Grid.
<%@ 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();
}
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Was able to get it working . My error was
<TemplateSettings TemplateId="BuTemplate" EditTemplateId="BuTemplate" />
It should be
<TemplateSettings EditTemplateId="BuTemplate" />
The addition of TemplateID does not allow to display the stored value on the screen.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0