8 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 09 May 2008, 06:50 AM
0

GrZeCh
Top achievements
Rank 2
answered on 09 May 2008, 07:47 AM
already been there and I had problem with accessing controls in EditForm under ItemCommand event. Can You maybe give me an example?
0

Princy
Top achievements
Rank 2
answered on 09 May 2008, 07:57 AM
Hi,
Try accessing the DropDownList control in the ItemDataBound event as shown below.
CS:
Thanks
Princy.
Try accessing the DropDownList control in the ItemDataBound event as shown below.
CS:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) |
{ |
if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode)) |
{ |
GridEditFormItem edititem = (GridEditFormItem)e.Item; |
DropDownList ddl = (DropDownList)edititem.FindControl("DropDownList"); |
} |
} |
Thanks
Princy.
0

GrZeCh
Top achievements
Rank 2
answered on 09 May 2008, 08:11 AM
It works but how can I check what action is performed (editing or adding new item)?
0
Accepted
Hello GrZeCh,
I think that the information from this help article will help you determine the edit/insert mode inside the ItemCreated/ItemDataBound handlers of RadGrid:
http://www.telerik.com/help/aspnet-ajax/grddistinguisheditinsertmodeonitemcreateditemdatabound.html
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
I think that the information from this help article will help you determine the edit/insert mode inside the ItemCreated/ItemDataBound handlers of RadGrid:
http://www.telerik.com/help/aspnet-ajax/grddistinguisheditinsertmodeonitemcreateditemdatabound.html
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0

GrZeCh
Top achievements
Rank 2
answered on 09 May 2008, 08:25 AM
Yes. Thats exactly what I needed.
Few minutes ago I solved my problem using this:
but I use code from URL given by You
Few minutes ago I solved my problem using this:
if (e.Item.DataItem is GridInsertionObject) |
{ |
} |
else if (e.Item.DataItem is DataRowView) |
{ |
} |
but I use code from URL given by You
0

Anto
Top achievements
Rank 1
answered on 02 Jul 2008, 03:31 AM
Hi there...
Inserting data is not a problem.
But when I update the data, there's an error : "Object reference not set to an instance of an object"
My ASPX :
<EditFormSettings CaptionFormatString="Rubah Project: {0}" CaptionDataField="nama_proyek_en" EditFormType="template" FormTableStyle-Width="600">
<PopUpSettings ScrollBars="None" />
<EditColumn ButtonType="ImageButton" InsertImageUrl="~/images/icon_ok.gif" EditImageUrl="~/images/icon_ok.gif" CancelImageUrl="~/images/icon_cancel.gif" EditText="Ubah" HeaderText="Silakan merubah data proyek :" UniqueName="EditCommandColumn1" UpdateText="Simpan">
</EditColumn>
<FormTemplate>
<table border="0">
<tr>
<td style="width:120px;">Nama Proyek (English)</td>
<td>:</td>
<td><telerik:RadTextBox ID="txtNamaProyekEn" runat="server" Text='<%#IIf(DataBinder.Eval(Container.DataItem, "nama_proyek_en") Is DBNull.Value, "", Eval("nama_proyek_en"))%>' EmptyMessage="Masukkan nama proyek dlm Bahasa Inggris" Width="200" MaxLength="150" ></telerik:RadTextBox></td>
</tr>
<tr>
<td style="width:120px;">Nama Proyek (Indo)</td>
<td>:</td>
<td><telerik:RadTextBox ID="txtNamaProyekID" runat="server" Text='<%#IIf(DataBinder.Eval(Container.DataItem, "nama_proyek_id") Is DBNull.Value, "", Eval("nama_proyek_id"))%>' EmptyMessage="Masukkan nama proyek dlm Bahasa Indonesia" Width="200" MaxLength="150" ></telerik:RadTextBox></td>
</tr>
<tr>
<td style="width:120px;">Lokasi Proyek</td>
<td>:</td>
<td><telerik:RadTextBox ID="txtLokasi" runat="server" Text='<%#IIf(DataBinder.Eval(Container.DataItem, "location") Is DBNull.Value, "", Eval("location"))%>' EmptyMessage="Masukkan lokasi proyek" Width="150" MaxLength="100" ></telerik:RadTextBox></td>
</tr>
<tr>
<td style="width:120px;">Tanggal</td>
<td>:</td>
<td><telerik:RadDatePicker ID="txtTanggal" runat="server" SelectedDate='<%#IIf(DataBinder.Eval(Container.DataItem, "tanggal") is DBNull.Value, Datetime.now, Eval("tanggal")) %>' Skin="WebBlue"></telerik:RadDatePicker></td>
</tr>
<tr>
<td colspan="3">
<asp:ImageButton ID="imgSave" runat="server" ImageUrl="~/images/icon_ok.gif" CommandName='<%# IIf( DataBinder.Eval(Container, "OwnerTableView.IsItemInserted"), "PerformInsert", "Update") %>' ToolTip='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Tambah", "Ubah")%>' />
<asp:ImageButton ID="imgCancel" runat="server" ImageUrl="~/images/icon_cancel.gif" CommandName="Cancel" ToolTip="Batal" />
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
Here is My VB :
Protected Sub rgAll_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgAll.ItemDataBound
If TypeOf e.Item.DataItem Is GridInsertionObject Then
Dim objEditFormItem As GridEditableItem = CType(e.Item, GridEditableItem)
Dim sqlProjectAdd As New SqlCommand("sp_ProjectAdd", myConn)
sqlProjectAdd.CommandType = Data.CommandType.StoredProcedure
sqlProjectAdd.Parameters.AddWithValue("@nama_proyek_en", CType(objEditFormItem.FindControl("txtNamaProyekEn"), RadTextBox).Text)
Try
myConn.Open()
sqlProjectAdd.ExecuteNonQuery()
myConn.Close()
rgAll.DataBind()
Catch ex As SqlException
lblInfo.Text = "Error saving data : " & ex.Message & "<br \>"
lblInfo.Visible = True
End Try
myConn.Close()
ElseIf TypeOf e.Item.DataItem Is DataRowView Then
Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
Dim sqlProjectEdit As New SqlCommand("sp_ProjectEdit", myConn)
sqlProjectEdit.CommandType = Data.CommandType.StoredProcedure
sqlProjectEdit.Parameters.AddWithValue("@project_code", rgAll.MasterTableView.DataKeyValues(e.Item.ItemIndex)("project_code").ToString)
sqlProjectEdit.Parameters.AddWithValue("@nama_proyek_en", CType(editedItem.FindControl("txtNamaProyekEn"), RadTextBox).Text)
Try
myConn.Open()
sqlProjectEdit.ExecuteNonQuery()
myConn.Close()
rgAll.DataBind()
Catch ex As SqlException
lblInfo.Text = "Error saving data : " & ex.Message & "<br \>"
lblInfo.Visible = True
End Try
myConn.Close()
End If
End Sub
The error comes when I tried to get the value from :
CType(editedItem.FindControl("txtNamaProyekEn"), RadTextBox).Text
Can someone tell me where do I miss?
Inserting data is not a problem.
But when I update the data, there's an error : "Object reference not set to an instance of an object"
My ASPX :
<EditFormSettings CaptionFormatString="Rubah Project: {0}" CaptionDataField="nama_proyek_en" EditFormType="template" FormTableStyle-Width="600">
<PopUpSettings ScrollBars="None" />
<EditColumn ButtonType="ImageButton" InsertImageUrl="~/images/icon_ok.gif" EditImageUrl="~/images/icon_ok.gif" CancelImageUrl="~/images/icon_cancel.gif" EditText="Ubah" HeaderText="Silakan merubah data proyek :" UniqueName="EditCommandColumn1" UpdateText="Simpan">
</EditColumn>
<FormTemplate>
<table border="0">
<tr>
<td style="width:120px;">Nama Proyek (English)</td>
<td>:</td>
<td><telerik:RadTextBox ID="txtNamaProyekEn" runat="server" Text='<%#IIf(DataBinder.Eval(Container.DataItem, "nama_proyek_en") Is DBNull.Value, "", Eval("nama_proyek_en"))%>' EmptyMessage="Masukkan nama proyek dlm Bahasa Inggris" Width="200" MaxLength="150" ></telerik:RadTextBox></td>
</tr>
<tr>
<td style="width:120px;">Nama Proyek (Indo)</td>
<td>:</td>
<td><telerik:RadTextBox ID="txtNamaProyekID" runat="server" Text='<%#IIf(DataBinder.Eval(Container.DataItem, "nama_proyek_id") Is DBNull.Value, "", Eval("nama_proyek_id"))%>' EmptyMessage="Masukkan nama proyek dlm Bahasa Indonesia" Width="200" MaxLength="150" ></telerik:RadTextBox></td>
</tr>
<tr>
<td style="width:120px;">Lokasi Proyek</td>
<td>:</td>
<td><telerik:RadTextBox ID="txtLokasi" runat="server" Text='<%#IIf(DataBinder.Eval(Container.DataItem, "location") Is DBNull.Value, "", Eval("location"))%>' EmptyMessage="Masukkan lokasi proyek" Width="150" MaxLength="100" ></telerik:RadTextBox></td>
</tr>
<tr>
<td style="width:120px;">Tanggal</td>
<td>:</td>
<td><telerik:RadDatePicker ID="txtTanggal" runat="server" SelectedDate='<%#IIf(DataBinder.Eval(Container.DataItem, "tanggal") is DBNull.Value, Datetime.now, Eval("tanggal")) %>' Skin="WebBlue"></telerik:RadDatePicker></td>
</tr>
<tr>
<td colspan="3">
<asp:ImageButton ID="imgSave" runat="server" ImageUrl="~/images/icon_ok.gif" CommandName='<%# IIf( DataBinder.Eval(Container, "OwnerTableView.IsItemInserted"), "PerformInsert", "Update") %>' ToolTip='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Tambah", "Ubah")%>' />
<asp:ImageButton ID="imgCancel" runat="server" ImageUrl="~/images/icon_cancel.gif" CommandName="Cancel" ToolTip="Batal" />
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
Here is My VB :
Protected Sub rgAll_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgAll.ItemDataBound
If TypeOf e.Item.DataItem Is GridInsertionObject Then
Dim objEditFormItem As GridEditableItem = CType(e.Item, GridEditableItem)
Dim sqlProjectAdd As New SqlCommand("sp_ProjectAdd", myConn)
sqlProjectAdd.CommandType = Data.CommandType.StoredProcedure
sqlProjectAdd.Parameters.AddWithValue("@nama_proyek_en", CType(objEditFormItem.FindControl("txtNamaProyekEn"), RadTextBox).Text)
Try
myConn.Open()
sqlProjectAdd.ExecuteNonQuery()
myConn.Close()
rgAll.DataBind()
Catch ex As SqlException
lblInfo.Text = "Error saving data : " & ex.Message & "<br \>"
lblInfo.Visible = True
End Try
myConn.Close()
ElseIf TypeOf e.Item.DataItem Is DataRowView Then
Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
Dim sqlProjectEdit As New SqlCommand("sp_ProjectEdit", myConn)
sqlProjectEdit.CommandType = Data.CommandType.StoredProcedure
sqlProjectEdit.Parameters.AddWithValue("@project_code", rgAll.MasterTableView.DataKeyValues(e.Item.ItemIndex)("project_code").ToString)
sqlProjectEdit.Parameters.AddWithValue("@nama_proyek_en", CType(editedItem.FindControl("txtNamaProyekEn"), RadTextBox).Text)
Try
myConn.Open()
sqlProjectEdit.ExecuteNonQuery()
myConn.Close()
rgAll.DataBind()
Catch ex As SqlException
lblInfo.Text = "Error saving data : " & ex.Message & "<br \>"
lblInfo.Visible = True
End Try
myConn.Close()
End If
End Sub
The error comes when I tried to get the value from :
CType(editedItem.FindControl("txtNamaProyekEn"), RadTextBox).Text
Can someone tell me where do I miss?
0
Hello Anto,
Based on the code snippet, it is hard to determine what is causing the exception at your end. To further address the issue, it will be best if you open a formal support ticket, and send us a small project sample, demonstrating the behavior.
We will review it locally, and advise you further.
Best wishes,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Based on the code snippet, it is hard to determine what is causing the exception at your end. To further address the issue, it will be best if you open a formal support ticket, and send us a small project sample, demonstrating the behavior.
We will review it locally, and advise you further.
Best wishes,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center