This is a migrated thread and some comments may be shown as answers.

[Solved] GridEditFormInsertItem URGENT

1 Answer 147 Views
Grid
This is a migrated thread and some comments may be shown as answers.
maha
Top achievements
Rank 1
maha asked on 27 Jun 2008, 06:45 PM
I have SQLDataSource

<

asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ AppSettings:ConnectionInfo %>"

runat="server" SelectCommand="prcGetMTSCorrespondentContact" DeleteCommand="prcAddMTSCorrespondentContact"

DeleteCommandType="StoredProcedure" InsertCommandType="StoredProcedure" SelectCommandType="StoredProcedure"

UpdateCommandType="StoredProcedure" OnSelecting="SqlDataSource1_Selecting" OnDeleting="SqlDataSource1_Deleting"

OnUpdating="SqlDataSource1_Updating" UpdateCommand="prcAddMTSCorrespondentContact"

InsertCommand="prcAddMTSCorrespondentContact" OnInserting="SqlDataSource1_Inserting">

<DeleteParameters>

<asp:Parameter Name="ContactID" Type="Int32" />

<asp:Parameter Name="Firm" Type="Int32" />

<asp:Parameter Name="CorrespondentCode" Type="Int32" />

<asp:Parameter Name="Delete" Type="Int32" DefaultValue="1" />

</DeleteParameters>

<SelectParameters>

<asp:Parameter Name="Firm" Type="String" />

<asp:Parameter Name="CorrespondentCode" Type="String" />

</SelectParameters>

<UpdateParameters>

<asp:Parameter Direction="ReturnValue" Name="RETURN_VALUE" Type="Int32" />

<asp:Parameter Name="ContactID" Type="Int32" />

<asp:Parameter Name="Firm" Type="String" />

<asp:Parameter Name="CorrespondentCode" Type="String" />

<asp:ControlParameter Name="DepartmentName" ControlID="txtDepartmentName" PropertyName="Text"

Type="String" />

<asp:ControlParameter Name="DepartmentNote" ControlID="txtDepartmentNote" PropertyName="Text"

Type="String" />

<asp:ControlParameter Name="ContactPerson" ControlID="txtContactPerson" PropertyName="Text"

Type="String" />

<asp:ControlParameter Name="Telephone" ControlID="txtTelephone" PropertyName="Text"

Type="String" />

<asp:ControlParameter Name="Telephone2" ControlID="txtTelephone2" PropertyName="Text"

Type="String" />

<asp:ControlParameter Name="Fax" ControlID="txtFax" PropertyName="Text"

Type="String" />

<asp:ControlParameter Name="Email" ControlID="txtEmail" PropertyName="Text" Type="String" />

<asp:ControlParameter Name="Email2" ControlID="txtEmail2" PropertyName="Text" Type="String" />

<asp:ControlParameter Name="Sequence" ControlID="txtSequence" PropertyName="Text"

Type="String" />

<asp:Parameter Name="Delete" Type="Int32" DefaultValue="0" />

</UpdateParameters>

<InsertParameters>

<asp:Parameter Direction="ReturnValue" Name="RETURN_VALUE" Type="Int32" />

<asp:Parameter Name="ContactID" Type="Int32" DefaultValue="0" />

<asp:Parameter Name="Firm" Type="String" />

<asp:Parameter Name="CorrespondentCode" Type="String" />

<asp:ControlParameter Name="DepartmentName" ControlID="txtDepartmentName" PropertyName="Text"

Type="String" />

<asp:ControlParameter Name="DepartmentNote" ControlID="txtDepartmentNote" PropertyName="Text"

Type="String" />

<asp:ControlParameter Name="ContactPerson" ControlID="txtContactPerson" PropertyName="Text"

Type="String" />

<asp:ControlParameter Name="Telephone" ControlID="txtTelephone" PropertyName="Text"

Type="String" />

<asp:ControlParameter Name="Telephone2" ControlID="txtTelephone2" PropertyName="Text"

Type="String" />

<asp:ControlParameter Name="Fax" ControlID="txtFax" PropertyName="Text"

Type="String" />

<asp:ControlParameter Name="Email" ControlID="txtEmail" PropertyName="Text" Type="String" />

<asp:ControlParameter Name="Email2" ControlID="txtEmail2" PropertyName="Text" Type="String" />

<asp:ControlParameter Name="Sequence" ControlID="txtSequence" PropertyName="Text"

Type="String" />

<asp:Parameter Name="Delete" Type="Int32" DefaultValue="0" />

</InsertParameters>

</asp:SqlDataSource>



and the grid DataSource is set to the SQLDataSource.


Update is working fine.But insert is not working.
It says 
Could not find control 'txtDepartmentName' in ControlParameter 'DepartmentName'. 
Below is my DepartmentName column definition

<

telerik:GridTemplateColumn HeaderText="Department Name" UniqueName="DepartmentName">

<ItemTemplate>

<asp:Label ID="lblDepartmentName" runat="server" Text='<%# Bind("DepartmentName") %>'></asp:Label>

</ItemTemplate>

<EditItemTemplate>

<span style="color:Red;text-align:left;font-size:medium">*</span>

<asp:TextBox ID="txtDepartmentName" runat="server" Text='<%# Bind("DepartmentName") %>' Width="200" MaxLength="100"></asp:TextBox>

<asp:RequiredFieldValidator ID="rfvTxtDepartmentName" ControlToValidate="txtDepartmentName"

ErrorMessage="Please enter Department Name!" runat="server" Display="None">

</asp:RequiredFieldValidator>

</EditItemTemplate>

</telerik:GridTemplateColumn>

 and this is my codebehind file

protected

void grdContacts_ItemCommand(object source, GridCommandEventArgs e)

{

if (e.CommandName == "Update")

{

GridEditFormItem item = (GridEditFormItem)grdContacts.MasterTableView.GetItems(GridItemType.EditFormItem)[e.Item.ItemIndex];

foreach (Parameter param in SqlDataSource1.UpdateParameters)

{

ControlParameter cParam = param as ControlParameter;

if (cParam != null)

{

(cParam).ControlID = item.FindControl(cParam.ControlID).UniqueID;

}

}

}

else if (e.CommandName == "PerformInsert")

{

GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item;

foreach (Parameter param in SqlDataSource1.UpdateParameters)

{

ControlParameter cParam = param as ControlParameter;

if (cParam != null)

{

(cParam).ControlID = item.FindControl(cParam.ControlID).UniqueID;

}

}

}

}

1 Answer, 1 is accepted

Sort by
0
maha
Top achievements
Rank 1
answered on 27 Jun 2008, 09:51 PM
Issue is fixed.
Tags
Grid
Asked by
maha
Top achievements
Rank 1
Answers by
maha
Top achievements
Rank 1
Share this question
or