can i get 2 values against dopostback with Page.ClientScript.GetPostBackClientHyperlink

Viewed 26

I am creating a page in asp.net in which i am using a button to populate some results on a GridView but after that i want a function to take place on click which can give me 2 values 1 is the row index and 2nd is column index but for some reason i am not able to get the column index

here is the code

on aspx side

<asp:GridView runat="server" ID="GridView1" AutoPostBack="true" OnRowDataBound="OnRowDataBound"
            AutoGenerateColumns="false"
            OnSelectedIndexChanged="OnSelectedIndexChanged" OnRowCommand="GridView1_RowCommand">
            <Columns>
                <asp:ButtonField DataTextField="T" HeaderText="Token"/>
                
            </Columns>
        </asp:GridView>

on aspx.cs side

protected void OnRowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(GridView1, "$" + e.Row.RowIndex);
            e.Row.Attributes["style"] = "cursor:pointer";
        }
    }
    protected void OnSelectedIndexChanged(object sender, EventArgs e)
    {
        
        int index = GridView1.SelectedRow.RowIndex;
        string name = GridView1.SelectedRow.Cells[0].Text;
        string country = GridView1.SelectedRow.Cells[1].Text;
        string message = "Row Index: " + index + "\\nID: " + name + "\\nName: " + country;
        ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + message + "');", true);
    }

so when i run this page on the gridview i get that i have a javascript with __doPostBack which return the row index onclick but i need column index or column value for my next step

if there is anyway for me to get the column value let me know

0 Answers
Related