Vote count:
0
I am using Obout:Combobox as a dropdownlist inside gridview.
<asp:TemplateField HeaderText="Particular" HeaderStyle-Width="500px">
<ItemTemplate>
<cc1:ComboBox ID="ddlParticular" AutoPostBack="true" runat="server" SelectedValue="acc_IE_name"
DataSourceID="sd1" DataValueField="acc_IE_id" DataTextField="acc_IE_name" Width="500"
MenuWidth="500" AppendDataBoundItems="true" OnDataBound="ddlParticular_DataBound">
<ItemTemplate>
<div class="item c1">
<%# Eval("acc_IE_id")%></div>
<div class="item c2">
<%# Eval("acc_IE_name")%></div>
<div class="item c3">
<%# Eval("item_type") %></div>
</ItemTemplate>
</cc1:ComboBox>
</ItemTemplate>
<HeaderStyle Width="500px" />
</asp:TemplateField>
To bind dropdownlist I am using asp:SqlDataSource.
<asp:SqlDataSource ID="sd1" runat="server" ViewStateMode="Enabled" ConnectionString="<%$ ConnectionStrings:misConnectionString %>"
SelectCommand="select_account_income_expenses" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:SessionParameter Name="company_code" SessionField="company_code" Type="Int32" />
</SelectParameters>
Problem I am facing right now is that whenever I add a new row in gridview, items in dropdownlist in the previous row doesn't bind at all. It only binds in newly added row. Code for SetPreviousData() is following:
protected void SetPreviousData()
{
try
{
int rowIndex = 0;
if (ViewState["CurrentTable"] != null)
{
DataTable dt = (DataTable)ViewState["CurrentTable"];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
DropDownList ddlNature = (DropDownList)gvJournal.Rows[rowIndex].Cells[0].FindControl("ddlNature");
ComboBox ddlParticular = (ComboBox)gvJournal.Rows[rowIndex].Cells[1].FindControl("ddlParticular");
TextBox txtDebit = (TextBox)gvJournal.Rows[rowIndex].Cells[2].FindControl("txtDebit");
TextBox txtCredit = (TextBox)gvJournal.Rows[rowIndex].Cells[3].FindControl("txtCredit");
ddlNature.SelectedIndex = dt.Rows[i]["nature"] == DBNull.Value ? 0 : Convert.ToInt32(dt.Rows[i]["nature"]);
//SqlDataSource sd1 = (SqlDataSource)gvJournal.Rows[rowIndex].Cells[0].FindControl("sd1");
//ddlParticular.DataSource = sd1;
//ddlParticular.DataSourceID = sd1;
ddlParticular.DataBind();
ddlParticular.SelectedText = dt.Rows[i]["particular"].ToString();
txtDebit.Text = dt.Rows[i]["debit"].ToString();
txtCredit.Text = dt.Rows[i]["credit"].ToString();
rowIndex++;
}
}
}
}
catch (Exception ex)
{
}
}
I tried using ddlParticular.DataSource as well as ddlParticular.DataSourceID but it didn't work. The previous one throws Both DataSource and DataSourceID are defined on 'ddlParticular'. Remove one definition. error. I did search for similar problem but couldn't find any answer.
asked 57 secs ago
Dropdownlist inside gridview doesn't bind in previous gridview rows
Aucun commentaire:
Enregistrer un commentaire