Fusion Outsourcing Software Pvt. Ltd.
Top achievements
Rank 1
Fusion Outsourcing Software Pvt. Ltd.
asked on 08 Jun 2009, 08:21 AM
Hello Telerik,
I have a textbox on whose keyup event i m filling the grid.
I have successfully implemented this search.
the grid has 4 columns, "Edit" , "Name", "Town", "Delete".
The problem i am facing is, When i type the item to be searched in textbox, if no such item is present then i Click on "Add New Record" to add that.
Here i have got stuck.
I want that on Clicking "Add new Record" whatever text was there in textbox it should come in "Name" textbox which is opened in Grid for inserting purpose.
So , can you help me how to get it.
Thanks,
Chinmay Sharma.
I have a textbox on whose keyup event i m filling the grid.
I have successfully implemented this search.
the grid has 4 columns, "Edit" , "Name", "Town", "Delete".
The problem i am facing is, When i type the item to be searched in textbox, if no such item is present then i Click on "Add New Record" to add that.
Here i have got stuck.
I want that on Clicking "Add new Record" whatever text was there in textbox it should come in "Name" textbox which is opened in Grid for inserting purpose.
So , can you help me how to get it.
Thanks,
Chinmay Sharma.
5 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 08 Jun 2009, 09:53 AM
Hi Chinmay Sharma,
Try out the following code snippet.
ASPX:
CS:
Thanks,
Princy.
Try out the following code snippet.
ASPX:
| <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" DataSourceID="SqlDataSource1" |
| OnItemDataBound="RadGrid1_ItemDataBound"> |
| <MasterTableView DataSourceID="SqlDataSource1" AutoGenerateColumns="False" CommandItemDisplay="Top" EditMode="EditForms" > |
| <Columns> |
| . . . |
| <telerik:GridBoundColumn DataField="Name" HeaderText="Name" SortExpression="Name" |
| UniqueName="Name"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Town" HeaderText="Town" SortExpression="Town" |
| UniqueName="Town"> |
| </telerik:GridBoundColumn> |
| </Columns> |
| </MasterTableView> |
| </telerik:RadGrid> |
| <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> |
CS:
| protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if (e.Item.OwnerTableView.IsItemInserted && e.Item is GridEditFormInsertItem) |
| { |
| GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item; |
| TextBox textbox = (TextBox)item["Name"].Controls[0]; // Get the textbox |
| textbox.Text = TextBox1.Text; // Set the textbox value |
| } |
| } |
Thanks,
Princy.
0
Fusion Outsourcing Software Pvt. Ltd.
Top achievements
Rank 1
answered on 08 Jun 2009, 10:29 AM
Hello Princy,
Thanks for the reply. That helped me a lot.
Its perfectly working when i have EDITMODE="EditForms".
But i am having Inplace editing. So, i tried GridEditableItem instead of "GridEditFormInsertItem" both in both in IF condition and assignment statement and thats working correctly. If you think i did something wrong with that then please let me know.
Anyway, My problem is solved for now.
Thanks again.
Chinmay Sharma.
Thanks for the reply. That helped me a lot.
Its perfectly working when i have EDITMODE="EditForms".
But i am having Inplace editing. So, i tried GridEditableItem instead of "GridEditFormInsertItem" both in both in IF condition and assignment statement and thats working correctly. If you think i did something wrong with that then please let me know.
Anyway, My problem is solved for now.
Thanks again.
Chinmay Sharma.
0
Fusion Outsourcing Software Pvt. Ltd.
Top achievements
Rank 1
answered on 08 Jun 2009, 12:53 PM
Hi Princy,
Your last post helped me,
But now i am facing problem again,
In another Grid I have "DetailButton", "Edit", "firstname", "LastName" & 3 to 4 more columns like this. A seperate text box for this grid.
Now when textbox is empty(in my case "Type here to search") and i click "Add new record" it works fine, but when i have some text in text box and then i click "Add New Record", it shows an exception "Specified argument was out of the range of valid values. Parameter name: index". I am not sure why this problem has pop up, as it was working fine with another grid.
I have pasted the code below.
ASPX File
In above code i have just considered 3 Feilds "Details","Edit","FirstName". I am facing problem here too.
Below i have pasted ASPX.CS code:
Please Suggest me where i am having Problem.
Thanks,
Chinmay Sharma
Your last post helped me,
But now i am facing problem again,
In another Grid I have "DetailButton", "Edit", "firstname", "LastName" & 3 to 4 more columns like this. A seperate text box for this grid.
Now when textbox is empty(in my case "Type here to search") and i click "Add new record" it works fine, but when i have some text in text box and then i click "Add New Record", it shows an exception "Specified argument was out of the range of valid values. Parameter name: index". I am not sure why this problem has pop up, as it was working fine with another grid.
I have pasted the code below.
ASPX File
| <asp:TextBox ID="txt_contact_name" onkeyup="KeyUp();" runat="server" AutoCompleteType ="Disabled" Text="Type here to search" onblur = "DefaultText(this, event);" onfocus = "DefaultText(this, event);" style =" color:#BFC0BD"></asp:TextBox> |
| <telerik:RadGrid ID="Grid_contacts" AllowPaging="true" PageSize="25" Skin="Vista" runat="server" |
| OnNeedDataSource="Grid_contacts_NeedDataSource" Width="100%" AutoGenerateColumns="false" HorizontalAlign="NotSet" |
| OnUpdateCommand="Grid_contacts_UpdateCommand" OnInsertCommand="Grid_contacts_InsertCommand" OnDeleteCommand="Grid_contacts_DeleteCommand" OnSelectedIndexChanged="Grid_contacts_SelectedIndexChanged" OnItemDataBound="Grid_contacts_ItemDataBound"> |
| <PagerStyle Mode="NextPrevAndNumeric" /> |
| <MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="ContactID" EditMode ="InPlace"> |
| <Columns> |
| <telerik:GridButtonColumn Text="Details" CommandName="Select" HeaderText="View Details" /> |
| <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn" HeaderText="Edit"> |
| <ItemStyle CssClass="MyImageButton" /> |
| </telerik:GridEditCommandColumn> |
| <telerik:GridBoundColumn UniqueName="FirstName" HeaderText="FirstName" DataField="FirstName" ColumnEditorID = "Grid_contactsTextBox_FirstName"> |
| </telerik:GridBoundColumn> |
| </Columns> |
| <ExpandCollapseColumn Visible="False"> |
| <HeaderStyle Width="10px" /> |
| </ExpandCollapseColumn> |
| <RowIndicatorColumn Visible="False"> |
| <HeaderStyle Width="20px" /> |
| </RowIndicatorColumn> |
| </MasterTableView> |
| </telerik:RadGrid> |
| <telerik:GridTextBoxColumnEditor ID="Grid_contactsTextBox_FirstName" |
| runat="server"/> |
In above code i have just considered 3 Feilds "Details","Edit","FirstName". I am facing problem here too.
Below i have pasted ASPX.CS code:
| protected void Grid_contacts_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if (e.Item.OwnerTableView.IsItemInserted && e.Item is GridEditableItem) |
| { |
| GridEditableItem item = (GridEditableItem)e.Item; |
| if (txt_contact_name.Text == "Type here to search") |
| { |
| TextBox textbox = (TextBox)item["FirstName"].Controls[0]; // Get the textbox |
| textbox.Text = ""; |
| } |
| else |
| { |
| TextBox textbox = (TextBox)item["FirstName"].Controls[0]; // Get the textbox |
| textbox.Text = txt_contact_name.Text; // Set the textbox value |
| } |
| } |
| } |
Thanks,
Chinmay Sharma
0
Fusion Outsourcing Software Pvt. Ltd.
Top achievements
Rank 1
answered on 08 Jun 2009, 01:16 PM
Hi Princy,
I must further provide you more clearification about my problem stated in last post.
Suppose i have Chinmay as First name in my database,
and when in Textbox i just typed "ch" and then Clicked "Add new record" then this problem occurs.
But when i type "Chr" and then click on "Add new Record" then the exception is not popuped.
So problem occurs when the grid is not empty and neither the textbox and i clicked "Add new record".
Hope to have your reply soon.
Thanks,
Chinmay Sharma.
I must further provide you more clearification about my problem stated in last post.
Suppose i have Chinmay as First name in my database,
and when in Textbox i just typed "ch" and then Clicked "Add new record" then this problem occurs.
But when i type "Chr" and then click on "Add new Record" then the exception is not popuped.
So problem occurs when the grid is not empty and neither the textbox and i clicked "Add new record".
Hope to have your reply soon.
Thanks,
Chinmay Sharma.
0
Hello Chinmay,
Is it possible that there is some kind of check in your code which performs validation against the existing names in the data source? I am asking this question since you explained that the issue surfaces only when the typed string matches the starting part of the name field. This may conflict in some way with your logic and produce an error.
You may also debug the code inside the ItemDataBound event to see whether the textbox editor of the grid is referenced properly. Other than that, your implementation seems correct.
Best regards,
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Is it possible that there is some kind of check in your code which performs validation against the existing names in the data source? I am asking this question since you explained that the issue surfaces only when the typed string matches the starting part of the name field. This may conflict in some way with your logic and produce an error.
You may also debug the code inside the ItemDataBound event to see whether the textbox editor of the grid is referenced properly. Other than that, your implementation seems correct.
Best regards,
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.