Hi Aimee,
You need the ItemDataBound event. With this event we can control what goes
into each row of each column. Here is a sample based on the Pubs database.
I added a datagrid & added an edit/update/cancel column with the rest
auto-generate. Then I added the code below. It's just enough to show the
main function. When au_id starts with a 7, then one column is editable.
When it starts with an 8, then another is editable.
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.EditItem Then
If DataGrid1.EditItemIndex = e.Item.ItemIndex Then
Dim box As WebControls.TextBox
If Left(e.Item.DataItem("au_id"), 1) = 8 Then
box = New WebControls.TextBox
box.Text = e.Item.DataItem("au_lname")
e.Item.Cells(2).Controls.Add(box)
End If
If Left(e.Item.DataItem("au_id"), 1) = 7 Then
box = New WebControls.TextBox
box.Text = e.Item.DataItem("au_fname")
e.Item.Cells(3).Controls.Add(box)
End If
End If
End If
End Sub
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.EditCommand
DataGrid1.EditItemIndex = e.Item.ItemIndex
Bind()
End Sub
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.
--------------------