ASP.NET Podcast Show #14 - Editable Datagrid
Julie Lerman or her blog at Ziff-Davis.
Scott’s articles for creating an Editable Datagrid. Article 16 and Article 17.
ASP.NET Code:
<asp:DataGrid id="dgAction" runat="server" CssClass="form-label" Width="98%" AutoGenerateColumns="False"
UseAccessibleHeader="True" CellPadding="0" CellSpacing="0" BorderWidth="0">
<AlternatingItemStyle BackColor="Wheat"></AlternatingItemStyle>
<HeaderStyle BackColor="Silver"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Next Step">
<ItemTemplate>
<asp:TextBox Runat="server" ID="NextStep" Text='<%# Container.DataItem("NextStep")%>' cssclass="form-textbox" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Due Date">
<ItemTemplate>
<ew:CalendarPopup id="dpDueDate" runat="server" selectedDate='<%# DisplayNullDate(Convert.ToString(Container.DataItem("DueDate")))%>' Nullable="True" NullableLabelText=" " cssclass="form-textbox" Width="75px" ToolTip="Open Calendar" DisableTextboxEntry="False" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Completed Date">
<ItemTemplate>
<ew:CalendarPopup id="dpCompleteDate" runat="server" selectedDate='<%# DisplayNullDate(Convert.ToString(Container.DataItem("CompleteDate")))%>' Nullable="True" NullableLabelText=" " cssclass="form-textbox" Width="75px" ToolTip="Open Calendar" DisableTextboxEntry="False" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Remove">
<ItemTemplate>
<asp:checkbox ID="cbRemoveAction" Runat="server" />
<asp:Label ID="lblActionId" Runat="server" Visible="false" Text='<%# Container.DataItem("tbActionId")%>' />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
Binding the code:
Me.dgAction.DataSource = dtData
Me.dgAction.DataBind()
Finding controls:
For Each dgItem As DataGridItem In Me.dgAction.Items
strActionId = DirectCast(dgItem.FindControl("lblActionId"), System.Web.UI.WebControls.Label).Text
strAction = Trim(DirectCast(dgItem.FindControl("NextStep"), System.Web.UI.WebControls.TextBox).Text)
‘blah, blah, blah
Next
Getting the Drop Down ListBox
<asp:DropDownList Runat="server" ID="ddlTravelOfficeId" AutoPostBack="True" OnSelectedIndexChanged="ddlTravelOfficeId_SelectedIndexChanged"
CssClass="form-select" />
ASP.NET Code:
Protected Sub ddlTravelOfficeId_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim strOfficeId As String
Dim ddlOcrOffice As DropDownList = DirectCast(sender, DropDownList)
Dim rpItem As RepeaterItem = DirectCast(ddlOcrOffice.Parent, RepeaterItem)
Dim ddlOcrStaff As DropDownList = DirectCast(rpItem.FindControl("ddlTravelOcrStaffId"), DropDownList)
strOfficeId = Convert.ToString(ddlOcrOffice.SelectedValue)
SetOfficeMembers(strOfficeId, ddlOcrStaff)
End Sub