?ソ 
Hi Charles,
 
I think I understand what "devicekid" means by storing temporary data. I to 
have been looking for a way to do that.
Most of the time we just use a datagrid bound to a database or a xml file.
In my case, I'm using a datagrid that starts empty and the user has to insert 
data. I store the data in an Arraylist.
 
Now, how would I read all elements from the arraylist and send them to the 
database?
Thank you for your attention.
 
 
Here's my code for the database:
 
<code>
<codebehind>
Private Sub LoadGrid()

If (Session("Dados") Is Nothing) Then

Dim dt As DataTable

Dim dr As DataRow

Dim i As Integer

dt = New DataTable()

dt.Columns.Add(New DataColumn("Linha", GetType(String)))

dt.Columns.Add(New DataColumn("Ref", GetType(String)))

dt.Columns.Add(New DataColumn("Desc", GetType(String)))

dt.Columns.Add(New DataColumn("Unidade Medida", GetType(String)))

dt.Columns.Add(New DataColumn("Quantidade", GetType(String)))

'For i = 1 To 2

' dr = dt.NewRow()

' dr(0) = "Item " + i.ToString()

' dr(1) = "Item " + i.ToString()

' dr(2) = "Item " + i.ToString()

' dr(3) = "Item " + i.ToString()

' dr(4) = "Item " + i.ToString()

' dt.Rows.Add(dr)

'Next

Session("Dados") = dt

End If

'

With Me.dgMrLines

.DataSource = New DataView(Session("Dados"))

.DataBind()

End With

End Sub

'

'

Public Sub dgMrLines_ItemCommand(ByVal source As System.Object, ByVal e As 
System.Web.UI.WebControls.DataGridCommandEventArgs)

If e.CommandName = "Insert" Then

Dim dr As DataRow

dr = DirectCast(Session("Dados"), DataTable).NewRow()

dr(0) = DirectCast(e.Item.FindControl("txtLinha"), TextBox).Text

dr(1) = DirectCast(e.Item.FindControl("txtRef"), TextBox).Text

dr(2) = DirectCast(e.Item.FindControl("txtDesc"), TextBox).Text

dr(3) = DirectCast(e.Item.FindControl("txtUnit"), TextBox).Text

dr(4) = DirectCast(e.Item.FindControl("txtQty"), TextBox).Text

DirectCast(Session("Dados"), DataTable).Rows.Add(dr)

Call Me.LoadGrid()

End If

End Sub

'

'

Public Sub dgMrLines_DeleteCommand(ByVal source As System.Object, ByVal e As 
System.Web.UI.WebControls.DataGridCommandEventArgs)

DirectCast(Session("Dados"), DataTable).Rows.RemoveAt(e.Item.ItemIndex)

Call Me.LoadGrid()

End Sub

</codebehind>

 

 

<aspx code>

 <asp:DataGrid id="dgMrLines" OnItemCommand="dgMrLines_ItemCommand" 
OnDeleteCommand="dgMrLines_DeleteCommand" style="Z-INDEX: 101; LEFT: 22px; 
POSITION: absolute; TOP: 19px" runat="server" BorderColor="#DEDFDE" 
BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4" 
GridLines="Vertical" ForeColor="Black" Font-Names="Arial" Font-Size="X-Small" 
AutoGenerateColumns="False" ShowFooter="True">
    <SelectedItemStyle Font-Bold="True" ForeColor="White" 
BackColor="#CE5D5A"></SelectedItemStyle>
    <AlternatingItemStyle BackColor="White"></AlternatingItemStyle>
    <ItemStyle BackColor="#F7F7DE"></ItemStyle>
    <HeaderStyle Font-Bold="True" ForeColor="White" 
BackColor="#6B696B"></HeaderStyle>
    <FooterStyle BackColor="#CCCC99"></FooterStyle>
    <Columns>
     <asp:TemplateColumn HeaderText="Linha">
      <ItemTemplate>
       <asp:Label id="lblLinha" runat="server">
        <%# DataBinder.Eval(Container.DataItem, "Linha")%>
       </asp:Label>
      </ItemTemplate>
      <FooterTemplate>
       <asp:TextBox id="txtLinha" runat="server"></asp:TextBox>
      </FooterTemplate>
     </asp:TemplateColumn>
     <asp:TemplateColumn HeaderText="Ref">
      <ItemTemplate>
       <asp:Label id="lblRef" runat="server">
        <%# DataBinder.Eval(Container.DataItem, "Ref")%>
       </asp:Label>
      </ItemTemplate>
      <FooterTemplate>
       <asp:TextBox id="txtRef" runat="server"></asp:TextBox>
      </FooterTemplate>
     </asp:TemplateColumn>
     <asp:TemplateColumn HeaderText="Desc">
      <ItemTemplate>
       <asp:Label id="lblDesc" runat="server">
        <%# DataBinder.Eval(Container.DataItem, "Desc")%>
       </asp:Label>
      </ItemTemplate>
      <FooterTemplate>
       <asp:TextBox id="txtDesc" runat="server"></asp:TextBox>
      </FooterTemplate>
     </asp:TemplateColumn>
     <asp:TemplateColumn HeaderText="Unidade Medida">
      <ItemTemplate>
       <asp:Label id="lblUnit" runat="server">
        <%# DataBinder.Eval(Container.DataItem, "Unidade Medida")%>
       </asp:Label>
      </ItemTemplate>
      <FooterTemplate>
       <asp:TextBox id="txtUnit" runat="server"></asp:TextBox>
      </FooterTemplate>
     </asp:TemplateColumn>
     <asp:TemplateColumn HeaderText="Quantidade">
      <ItemTemplate>
       <asp:Label id="lblQty" runat="server">
        <%# DataBinder.Eval(Container.DataItem, "Quantidade")%>
       </asp:Label>
      </ItemTemplate>
      <FooterTemplate>
       <asp:TextBox id="txtQty" runat="server"></asp:TextBox>
      </FooterTemplate>
     </asp:TemplateColumn>
     <asp:TemplateColumn>
      <ItemTemplate>
       <asp:Button id="btnDelete" runat="server" Width="20px" 
CommandName="Delete" Text="X"></asp:Button>
      </ItemTemplate>
      <FooterTemplate>
       <asp:Button id="btnInsert" runat="server" Width="20px" 
CommandName="Insert" Text="+"></asp:Button>
      </FooterTemplate>
     </asp:TemplateColumn>
    </Columns>
    <PagerStyle HorizontalAlign="Right" ForeColor="Black" BackColor="#F7F7DE" 
Mode="NumericPages"></PagerStyle>
   </asp:DataGrid>

</aspx code>

</code>

 

 

-----Original Message-----
From: Charles Carroll [mailto:[EMAIL PROTECTED] 
Sent: quinta-feira, 6 de Janeiro de 2005 8:13
To: [email protected]
Subject: Re: [AspNetAnyQuestionIsOk] datagrid


http://www.learnasp.com/freebook/learn/datagridtrick-codeonly.aspx
is an example of syntax to add columns dynamically.

Clarify specifically what you mean by storing data from webform. There
are several ways to??interpret that request. Then we can answer.


On Wed, 5 Jan 2005 08:01:59 +0000 (GMT), hitesh c <[EMAIL PROTECTED]> wrote:
>  hi,
>     how can we dynamically add columns to the datagrid
>  and aslo how can we make it to store temporary data
>  from webform


  _____  

Yahoo! Groups Links


*       To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
  

*       To unsubscribe from this group, send an email to:
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> 
  

*       Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service 
<http://docs.yahoo.com/info/terms/> . 




[Non-text portions of this message have been removed]






 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to