0

I have used jQuery in my website. I have a navigation bar in my header. When user clicks any link given in my menu bar. It calls my javascript function..and a dialog box appears having a form. For example I have a form say "Add Country". When user clicks the link "Add country"

A form appears in a dialog box. And then user will be able to add country in the given form.

Now i have a gridview in my page..where im managing my data. My country table has 3 coloumns. Coutry Code, Country Name, Description. I have bound country table as sql datasource with that gridview. I have added a asp button as a template item in that gridview as well. All i want to do is..When user clicks the edit button of the particular row in my grid view..i would get the countryID of that row. And i want to call that country FORM again..where user will be able to edit. How can i call my java script function in c# code so that i would be able to call that form again ? I m relatively a new programmer. Anmy detailed guidance will be highly appreciated.

Lets suppose i have :

protected void EditSeriesButton(object sender, EventArgs e)
{    
    Button btn = (Button)sender;
    GridViewRow row = (GridViewRow)btn.NamingContainer;
    int countryID =Convert.ToInt32(CountryGridView.DataKeys[row.RowIndex].Value);

    //Here i have got the id of that row. Now i want to call the function of my
    //javascript so that i can call my country form.
    //Just please guide me how to call javascript function here to open my 
    // dialog box.
    //i will do rest of the things.
}

Please help me as soon as possible!!

Regards,

3

1 Answer 1

1

You can use gridview's rowdatabound event to add a onclick attribute to that button to call the javascript function:

protected void CountryGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        int countryID = Convert.ToInt32(CountryGridView.DataKeys[e.Row.RowIndex].Value);
        Button btnButton = (Button)e.Row.FindControl("btnName");
        btnButton.OnClientClick = "return Dosomething('"+countryID+"');";
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.