We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Buttun in a GGC

Dear all, i''ve put an ASP button in a template column (since i didn''t manage to use the celltype of the grid ...). I want to use this button to do a action on the actual record using the primary key. How can I catch : - the event raised by this button ? - the row of the actual button ? Thanks in advance, Chris

9 Replies

RA Ramu Syncfusion Team June 23, 2006 07:56 PM UTC

Hi Chris, You can catch an event raised by defining the OnClick event handler for the button inside the template in the aspx and you can retreive the row and its record inside this event as shown in the below code. Here is the code snippet to catch the event raised by the button. In the aspx page: [aspx] [C#] protected void btnSubmit_Click(object sender, EventArgs e) { Button btn=(Button )sender; //To get the current row. GridRow row = (GridRow)btn.Parent.Parent; //To Retrive the current record of rhe row. Record rd = row.Record; //To retrive the primary key of the record. string str = rd.GetValue("CategoryID").ToString(); this.TextBox1.Text = str.ToString(); } Steps to create the sample: Step1: Added an ''UnboundColumn'' and and named it as “Submit” Step2: Right click the grid to edit the grid in template mode. Add the button to the item template of the “Submit” column in the grid. Step3: Define the onclick event for the Button. Step4: Get the primary key as illustrated in the ''btnSubmit_Click'' method. Please let us know if you have any further questions. Thanks, Ramu.K ButtonInTemplate


RA Ramu Syncfusion Team June 23, 2006 08:23 PM UTC

Hi Chris, The aspx code is not seen in the above post so I have replaced the “<” symbol with “$” symbol for you to have a look in this browser. Here is the aspx code. [aspx] $sfwg:GridColumnDescriptor Name="Submit"> $ItemTemplate> $asp:Button ID="btnSubmit" runat="server" Text="submit" OnClick="btnSubmit_Click" /> $/ItemTemplate> $/sfwg:GridColumnDescriptor> Thanks, Ramu.K


CH Chris June 26, 2006 08:14 AM UTC

Dear Ramu, thanks for your answer but the event isn''t fired... I use visual basic with the framework 1.1, may be this information will help. I defined my proc like that: Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) without defining the handler... I suppose it is created by the grid control ? Any more idea ? Chris


AD Administrator Syncfusion Team June 26, 2006 03:58 PM UTC

I''ve just found my event problem. Because of another part of code, the oninit proc was never called ! But now, I''ve problems with the record object in the btnSubmit_Click proc... I cannot access to the properties of the record. I have to use the cell object instead but I am not to sure if I can use it on hidden cells... Thanks for the help ! Chris >Dear Ramu, > >thanks for your answer but the event isn''t fired... >I use visual basic with the framework 1.1, may be this information will help. >I defined my proc like that: >Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) >without defining the handler... I suppose it is created by the grid control ? > >Any more idea ? > >Chris


RA Ramu Syncfusion Team June 26, 2006 06:17 PM UTC

Hi Chris, I am not sure. I understand, Are you saying that you are not able to access the rd.GetValue("CategoryID") record value from the grid inside this btn_Submit Event ?. where rd is the object of the Record for the row in which the button is present. Could you explain me where exactly you get the problem in accessing the record? So that we could get your problem solved as soon has possible. Also I have attached the vb sample in framework 1.1. Are you facing similar issue in this sample? You will have to update the .webinfo file based on where you install the sample, before you can run the project. Remember to mark the folder as an application in IIS before you open the project. ButtonInTemplate_vb_1.1 Thanks, Ramu.K


CH Chris June 27, 2006 09:53 AM UTC

Hi, this is exactly my problem ! I suppose this is due to the different datasources between you and me: I have a dataset with 2 datatables and 1 datarelation. Your example works perfectly.


CH Chris June 27, 2006 02:47 PM UTC

Since i have to use the cell object to access my primary key but i don''t want to see if, is there a way to mask a column with setting the property width to 0 ?


RA Ramu Syncfusion Team June 28, 2006 12:17 AM UTC

Hi Chris, I have created the sample with two tables Categories, Products joined by CategoryID field from the NWIND database. Please have a look at the attached sample. ButtonInTemplate_With_Relation The primary key column (ProductID) is not visible in grid. This is achieved by removing the specified column from the ''VisibleColumns'' collections. If this doesn’t solves the problem. Could you provide me the code snippet demonstrating the issue so that we could exactly get your problem be resolved. Thanks for your practice. Thanks, Ramu.K


AD Administrator Syncfusion Team June 30, 2006 09:45 AM UTC

Dear Ramu, thanks, it works fine ! The problem I had was just that I cannot access the object when debugging... When the code is executed, it works ! Thanks a lot, Chris >Hi Chris, > >I have created the sample with two tables Categories, Products joined by CategoryID field from the NWIND database. Please have a look at the attached sample. > >ButtonInTemplate_With_Relation > >The primary key column (ProductID) is not visible in grid. This is achieved by removing the specified column from the ''VisibleColumns'' collections. > >If this doesn’t solves the problem. Could you provide me the code snippet demonstrating the issue so that we could exactly get your problem be resolved. > >Thanks for your practice. > >Thanks, >Ramu.K

Loader.
Live Chat Icon For mobile
Up arrow icon