Hi makumbi,
Please refer below sample.
HTML
<asp:GridView ID="gvCustomer" runat="server" AutoGenerateColumns="False" Width="405px">
<Columns>
<asp:BoundField DataField="Id" HeaderText="CustomerId" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Country" HeaderText="Country" />
<asp:TemplateField>
<ItemTemplate>
<asp:HiddenField ID="hfId" runat="server" Value='<%# Eval("Id")%>' />
<asp:HiddenField ID="hfName" runat="server" Value='<%# Eval("Name")%>' />
<asp:HiddenField ID="hfCountry" runat="server" Value='<%# Eval("Country")%>' />
<asp:Button Text="View" runat="server" OnClick="OnViewDetails" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<input id="text" runat="server" />
<button onclick="talk()">
Talk It!</button>
<button onclick="listen()">
Voice</button>
<select id="Language">
<option value="en">English</option>
<option value="fr">French</option>
</select>
<p id="status" style="color: red">
</p>
<script src="webspeech.js" type="text/javascript"></script>
<script type="text/javascript">
var speaker, listener;
window.onload = function () {
ws = webSpeechNoConflict();
try {
speaker = new ws.Speaker();
speaker.onEnd(function () {
console.log('just finished talking...');
});
}
catch (ex) {
console.log(ex);
speaker = null;
document.getElementById("status").innerHTML = ex;
}
try {
listener = new ws.Listener();
}
catch (ex) {
console.log(ex);
listener = null;
document.getElementById("status").innerHTML = ex;
}
};
function talk() {
if (speaker) {
speaker.speak(document.getElementById("Language").value, document.getElementById("text").value);
}
}
function listen() {
if (listener) {
listener.listen(document.getElementById("Language").value, function (text) {
document.getElementById("text").value = text;
});
}
}
</script>
Namespace
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] {
new DataColumn("Id"),
new DataColumn("Name"),
new DataColumn("Country")});
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");
gvCustomer.DataSource = dt;
gvCustomer.DataBind();
}
}
protected void OnViewDetails(object sender, EventArgs e)
{
GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
string customerId = (row.FindControl("hfId") as HiddenField).Value;
string name = (row.FindControl("hfName") as HiddenField).Value;
string country = (row.FindControl("hfCountry") as HiddenField).Value;
string message = "CustomerId: " + customerId; message += "\\nName: " + name; message += "\\nCountry: " + country;
text.Value = name;
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + message + "');", true);
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn() {New DataColumn("Id"), New DataColumn("Name"), New DataColumn("Country")})
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")
gvCustomer.DataSource = dt
gvCustomer.DataBind()
End If
End Sub
Protected Sub OnViewDetails(ByVal sender As Object, ByVal e As EventArgs)
Dim row As GridViewRow = TryCast(TryCast(sender, Button).NamingContainer, GridViewRow)
Dim customerId As String = TryCast(row.FindControl("hfId"), HiddenField).Value
Dim name As String = TryCast(row.FindControl("hfName"), HiddenField).Value
Dim country As String = TryCast(row.FindControl("hfCountry"), HiddenField).Value
Dim message As String = "CustomerId: " & customerId
message += "\nName: " & name
message += "\nCountry: " & country
text.Value = name
ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('" & message & "');", True)
End Sub
Screenshot