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

calling javascript function from Silverlight app

3 Answers 47 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Brian Graves
Top achievements
Rank 1
Brian Graves asked on 14 May 2010, 11:13 PM
I've programatically created a column with a button in my RadGridView and have created an event handler for the button click: 

 


public
class GridViewImageButtonColumn : GridViewHyperlinkColumn

 

 

 

{

 

 

 

    public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)

 

 

     {

 

        Button btn = new Button();

 

 

         btn.Click +=

new RoutedEventHandler(btn_Click);

 

 

 

 

 

        return btn;

     }

 


I even found out how to call the pages javascript by using this code in my click event handler:

    void
btn_Click(object sender, RoutedEventArgs e)

 

 

     {

 

 

         HtmlPage.Window.Invoke("jsfunction", new string[] { rowData });

 

 

    }
}

However, I'm not sure how can I get the the RadGridView row data from the row that the button was clicked in. 

Questions:
1)  how do I find out which row number that I clicked on?
2)  how do I access each cell's data from each column in the row that I clicked?

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 15 May 2010, 06:55 AM
Hello,

Since the button is inside the row you can use DataContext property - just cast it to your object type and access desired property. You can use also this.DataControl.Items.IndexOf(((Button)sender).DataContext) to find the item index.

Sincerely yours,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Brian Graves
Top achievements
Rank 1
answered on 17 May 2010, 05:22 PM
Thanks but could you provide a C# example for the first thing you said (just cast it to your object type and access desired property)?  I'm not sure what object you are referring to.  How do I get the data from each column (specifying the name or column index)?
0
Vlad
Telerik team
answered on 18 May 2010, 07:08 AM
Hello,

You can try the code in your Button Click event handler. Sender argument is your button and DataContext of your button is your data item.

All the best,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Brian Graves
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Brian Graves
Top achievements
Rank 1
Share this question
or