I am trying to get a combobox in Edit form as a template.
Firstly I have a RadGrid in that there is a combobox.I binded that successfully.
Upto here there is no problem.But now I have a Edit template form which opens on click of update button.
Here I have two textbox and a combo as a template.I want to show all values in Edit combo that are present in grids combo.I can fetch that again from a database.But the selected value should be same as Grid's combo's selected value.
How to do that.I tried by findcontrol method.I am getting correct combo from edit form.
But when I bind that to database I am not getting.
my Error:
Add Event Listener is null or not an object
My ASPX:
Combobox1 for grid
Combobox2 for Edit Template.
<EditFormSettings EditFormType="Template">
<EditColumn UniqueName="EditCommandColumn1"></EditColumn>
<FormStyle BackColor="#ECFED8" />
<FormTemplate>
<table id="Table1" cellspacing="1" cellpadding="1" width="250" border="0">
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
Employee_Name:</td>
<td>
<asp:TextBox ID="TextBox10" Text='<%# Bind( "Employee_Name") %>' runat="server">
</asp:TextBox></td>
</tr>
<tr>
<td>
Designation:</td>
<td>
<asp:TextBox ID="TextBox11" Text='<%# Bind( "Employee_Designation") %>' runat="server">
</asp:TextBox></td>
</tr>
<tr><telerik:RadComboBox ID="RadComboBox3" runat="server"></telerik:RadComboBox>
</tr></td></td>
</tr>
</table>
<table style="width: 100%">
<tr>
<td align="right" colspan="2">
<asp:Button ID="Button1" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
</asp:Button>
<asp:Button ID="Button2" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel">
</asp:Button>
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
CS
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is Telerik.Web.UI.GridDataItem)
{
Telerik.Web.UI.RadComboBox cmb = (Telerik.Web.UI.RadComboBox)e.Item.FindControl("RadComboBox1");
SqlConnection = new SqlConnection("Server=ma;DataBase=Test;User=sa;Password=");
SqlDataAdapter da = new SqlDataAdapter("Select Employee_Id from Employee_Master", SqlConnection);
DataTable dt1 = new DataTable();
da.Fill(dt1);
//string[] options = { "OptionA", "OptionB", "OptionC" };
cmb.DataSource = dt1;
cmb.DataMember = "Employee_Id";
cmb.DataTextField = "Employee_Id";
//cmb.SelectedIndex = i;
cmb.DataBind();
cmb.SelectedItem.Text = dt1.Rows[i]["Employee_Id"].ToString();
i++;
}
if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
{
//GridEditFormItem editFormItem = e.Item as GridEditFormItem;
//GridDataItem parentItem = editFormItem.ParentItem;
//Telerik.Web.UI.RadComboBox box = editFormItem.FindControl("RadComboBox3") as Telerik.Web.UI.RadComboBox;
SqlConnection = new SqlConnection("Server=ma;DataBase=Test;User=sa;Password=");
SqlDataAdapter da1 = new SqlDataAdapter("Select Employee_Id from Employee_Master", SqlConnection);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
//box.DataTextField = parentItem["Employee_Name"].Text;
//box.DataSource = dt1;
//box.DataMember = "Employee_Id";
//box.DataTextField = "Employee_Id";
GridEditFormItem formItem = (GridEditFormItem)e.Item;
RadComboBox dropdown = (RadComboBox)formItem.FindControl("RadComboBox3");
dropdown.DataSource= dt1;
dropdown.DataTextField = "Employee_Id";
dropdown.DataValueField = "Employee_Id";
dropdown.SelectedValue = DataBinder.Eval(formItem.DataItem, "Employee_Id").ToString();
}
Thanks in advance,
-Mahesh