Hi sambath,
Check the below example to share the select GridView Row details in whats app.
HTML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnSelectedIndexChanged="OnSelectedIndexChanged">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Country" HeaderText="Country" />
<asp:ButtonField Text="Select" CommandName="Select" />
</Columns>
</asp:GridView>
<asp:LinkButton ID="lnkShare" Text="Share" runat="server" OnClick="lnkShare_Click" />
<script type="text/javascript">
function ShareOnWhatsApp(id, name, country) {
window.open('whatsapp://send?text=Reg No.: ' + id + ',Name: ' + name + ',Country: ' + country + '');
return false;
}
</script>
C#
protected int selectedIndex = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.AddRange(new System.Data.DataColumn[3] {
new System.Data.DataColumn("Id", typeof(int)),
new System.Data.DataColumn("Name", typeof(string)),
new System.Data.DataColumn("Country",typeof(string)) });
dt.Rows.Add(1, "John Hammond", "United States");
dt.Rows.Add(2, "Mudassar Khan", "India");
dt.Rows.Add(3, "Suzanne Mathews", "France");
dt.Rows.Add(4, "Robert Schidner", "Russia");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
selectedIndex = GridView1.SelectedIndex;
}
protected void lnkShare_Click(object sender, EventArgs e)
{
GridViewRow row = this.GridView1.Rows[selectedIndex];
string id = row.Cells[0].Text;
string name = row.Cells[1].Text;
string country = row.Cells[2].Text;
string script = "window.onload = function() { ShareOnWhatsApp('" + id + "','" + name + "','" + country + "'); };";
ClientScript.RegisterStartupScript(this.GetType(), "script", script, true);
}
VB.Net
Protected selectedIndex As Integer = 0
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not Me.IsPostBack Then
Dim dt As System.Data.DataTable = New System.Data.DataTable()
dt.Columns.AddRange(New System.Data.DataColumn(2) {New System.Data.DataColumn("Id", GetType(Integer)), New System.Data.DataColumn("Name", GetType(String)), New System.Data.DataColumn("Country", GetType(String))})
dt.Rows.Add(1, "John Hammond", "United States")
dt.Rows.Add(2, "Mudassar Khan", "India")
dt.Rows.Add(3, "Suzanne Mathews", "France")
dt.Rows.Add(4, "Robert Schidner", "Russia")
GridView1.DataSource = dt
GridView1.DataBind()
End If
End Sub
Protected Sub OnSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
selectedIndex = GridView1.SelectedIndex
End Sub
Protected Sub lnkShare_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim row As GridViewRow = Me.GridView1.Rows(selectedIndex)
Dim id As String = row.Cells(0).Text
Dim name As String = row.Cells(1).Text
Dim country As String = row.Cells(2).Text
Dim script As String = "window.onload = function() { ShareOnWhatsApp('" & id & "','" & name & "','" & country & "'); };"
ClientScript.RegisterStartupScript(Me.[GetType](), "script", script, True)
End Sub
On click of share button the selected row will be generated in the url as
whatsapp://send/?text=Reg No.: 1,Name: John Hammond,Country: United States