By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,887 Members | 1,429 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,887 IT Pros & Developers. It's quick & easy.

Datagrid based on arraylist not editable

P: n/a
I have a webform with a two-column datagrid based on an Arraylist. The
Arraylist draws the data for the two columns from two different tables
in an SQL database. The data is displayed in datagrid as expected but
when user clicks the Edit link, the cells do NOT turn into editable
text boxes. I actually need only the first column to be editable but
any ideas on getting the whole row editable would help at first.
Apologies for the amount of code that follows:
<asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 55px;
POSITION: absolute; TOP: 59px" runat="server" Font-Size="Smaller"
Font-Names="Arial" Height="120px" Width="400px" ShowHeader="True">
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton"
UpdateText="Update" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
</Columns>
</asp:datagrid>

CODE BEHIND:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

Me.SqlConnection1.ConnectionString = Global.ConnectionString
Me.SqlConnection2.ConnectionString = Global.ConnectionString

If Me.IsPostBack = False Then
Call FillDatagrid()
End If

End Sub

Function FillDatagrid()
Dim arrReportHeading As New ArrayList()
Dim strSQl As String
Dim strSQl2 As String
Dim cmdSubjectList As SqlClient.SqlCommand
Dim cmdTblNameList As SqlClient.SqlCommand

Dim dr As SqlClient.SqlDataReader
Dim dr2 As SqlClient.SqlDataReader

strSQl = "SELECT ReportDesignHeadings.* FROM
ReportDesignHeadings WHERE (((ReportID)=@ReportID) AND
((SchID)=@schID))"
cmdSubjectList = New SqlClient.SqlCommand(strSQl,
SqlConnection1)
cmdSubjectList.Parameters.Add("@ReportID",
SqlDbType.Int).Value = Session("ReportID")
cmdSubjectList.Parameters.Add("@schID", SqlDbType.Int).Value =
Session("id")
Me.SqlConnection1.Open()
dr = cmdSubjectList.ExecuteReader()
dr.Read()

strSQl2 = "SELECT SubjectOrder.* FROM SubjectOrder WHERE
(((ReportID)=@ReportID) AND ((SchID)=@schID))"
cmdTblNameList = New SqlClient.SqlCommand(strSQl2,
SqlConnection2)
cmdTblNameList.Parameters.Add("@ReportID",
SqlDbType.Int).Value = Session("ReportID")
cmdTblNameList.Parameters.Add("@schID", SqlDbType.Int).Value =
Session("id")
Me.SqlConnection2.Open()
dr2 = cmdTblNameList.ExecuteReader()
dr2.Read()
arrReportHeading.Add(New ChangeHeadings((dr2.Item("Sub1")),
(dr.Item("sub1"))))
arrReportHeading.Add(New ChangeHeadings((dr2.Item("Sub2")),
(dr.Item("sub2"))))
arrReportHeading.Add(New ChangeHeadings((dr2.Item("Sub3")),
(dr.Item("sub3"))))
arrReportHeading.Add(New ChangeHeadings((dr2.Item("Sub4")),
(dr.Item("sub4"))))
arrReportHeading.Add(New ChangeHeadings((dr2.Item("Sub5")),
(dr.Item("sub5"))))

' etc, etc, etc. to "Sub26" and "sub26"

DataGrid1.DataSource = arrReportHeading
DataGrid1.DataBind()

dr.Close()
dr2.Close()
cmdSubjectList.Dispose()
cmdTblNameList.Dispose()
Me.SqlConnection1.Close()
Me.SqlConnection2.Close()
End Function

Public Class ChangeHeadings
Private _FldName As String
Private _FldLabel As String
Public Sub New(ByVal FldName As String, ByVal FldLabel As
String)
_FldName = FldName
_FldLabel = FldLabel
End Sub
Public ReadOnly Property FldName() As String
Get
Return _FldName
End Get
End Property
Public ReadOnly Property FldLabel() As String
Get
Return _FldLabel
End Get
End Property
End Class

Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DataGrid1.EditCommand
Me.DataGrid1.EditItemIndex = e.Item.ItemIndex
Call FillDatagrid()
Me.DataGrid1.Width = Unit.Pixel(550)
End Sub
Nov 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.