Datagrid based on arraylist not editable

Discussion in 'ASP .Net' started by DaveR, Nov 1, 2004.

  1. DaveR

    DaveR Guest

    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
    DaveR, Nov 1, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Saravanan Rathinavelu

    Iterate through ArrayList using an another ArrayList

    Saravanan Rathinavelu, Aug 16, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    2,738
    Natty Gur
    Aug 19, 2003
  2. Kaidi
    Replies:
    4
    Views:
    2,370
    Kaidi
    Jan 3, 2004
  3. xz
    Replies:
    16
    Views:
    2,368
  4. Philipp
    Replies:
    6
    Views:
    924
    Arne Vajhøj
    May 28, 2008
  5. Diane
    Replies:
    5
    Views:
    271
    alvinz_c
    Nov 9, 2005
Loading...

Share This Page