Hi Sue,
I'm not a client-side expert, but I think I've come up with a solution for
you. I added a column with a button that does not post back to the server.
Instead, it updates some fields outside of the datagrid. This is close to
what you said you wanted. One thing I skipped is that I put my client code
directly into the HTML when I should have used RegisterClientScriptBlock.
Here is my code which is based on the Pubs sample database.
This method will fail if the data contains single or double quote marks.
First the HTML
Notice that I added an HTML button with id=b1 and runat=server.
<HTML>
<HEAD>
<title>ClientSelect</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="
http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
<!--
function SetValues(id, fname, lname) {
document.all("TextBox1").value = id;
document.all("TextBox2").value = fname;
document.all("TextBox3").value = lname;
}
//-->
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
<asp:TextBox id="TextBox3" runat="server"></asp:TextBox><BR>
<BR>
<asp
ataGrid id="DataGrid1" runat="server">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<INPUT id="b1" runat="server" type="button"
value="Button">
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp
ataGrid>
</form>
</body>
</HTML>
Next the Code-Behind
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Bind()
End If
End Sub
Private Sub Bind()
Dim Qry1 As System.Data.SqlClient.SqlDataReader
Dim connectionString As String = "server='localhost';
trusted_connection=true; Database='pubs'"
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New
System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "SELECT au_id, au_lname, au_fname FROM
authors"
Dim sqlCommand As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlConnection.Open()
Qry1 =
sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
DataGrid1.DataSource = Qry1
DataGrid1.DataBind()
Qry1.Close()
sqlCommand.Dispose()
sqlConnection.Close()
sqlConnection.Dispose()
End Sub
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
Dim b As HtmlControls.HtmlInputButton
b = CType(e.Item.Cells(0).Controls(1), HtmlControls.HtmlInputButton)
b.Attributes.Add("onclick", "SetValues('" &
e.Item.DataItem("au_id") & "','" & e.Item.DataItem("au_fname") & "','" &
e.Item.DataItem("au_lname") & "');")
End If
End Sub
Does this answer your question?
Thank you, Mike
Microsoft, ASP.NET Support Professional
Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer's security.
This posting is provided "AS IS", with no warranties, and confers no rights.
--------------------