Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

datagrid

  Asked By: Jason    Date: Oct 31    Category: Asp.net    Views: 1076
  

is it possible to insert blank row in datagrid for sub titles?
something like that

a | 1 | 5 | 9
a | 1 | 5 | 9
title
a | 1 | 5 | 9
a | 1 | 5 | 9
title
a | 1 | 5 | 9
a | 1 | 5 | 9

Share: 

 

11 Answers Found

 
Answer #1    Answered By: Rochelle Elliott     Answered On: Oct 31

<PleaseForgiveMyIgnorance>
I am very new to ASP.NET, and this question intrigues me cuz I am sure there is a simple solution.

To solve this question I made my own page that dynamically added DataGrid controls to the page then inserted the title, every 5 rows of the DataTable that populated the DataGrid. It got complex and messy, so that wasn't elegant enough.

I am sure it would be possible to declare a new class inherited from System.Web.UI.WebControls.DataGrid and you would modify either the method .RenderControl or the method .Render and change the contents of the string being fed to the HtmlTextWriter to force a custom [title] row  every nth row.

If you got fancy, you could probably put in a couple properties to define the HTML of the title row and the rows on which the title row should appear.

Would that be the right approach? If it is.. can someone post any code sample (vb.net if possible) that shows a webcontrol having it's contents modified when being rendered?

 
Answer #2    Answered By: Silvia Chapman     Answered On: Oct 31
 
Answer #3    Answered By: Ty Thompson     Answered On: Oct 31

wat's the diff b/n


<%# databinder.eval(container.dataitem."column name")%>

and
<%# container.dataitem("column name") %>

 
Answer #4    Answered By: Grady Stewart     Answered On: Oct 31

wat's the diff b/n
<%# databinder.eval(container.dataitem."column name")%> Its
<%# databinder.eval(container.dataitem,"column name")%>

databinder.eval allows reflection which will make it easy to know the datatype
of the column and other properties. where as container.dataitem doesnt.


and
<%# container.dataitem("column name") %>

 
Answer #5    Answered By: Brendan Smith     Answered On: Oct 31

i am new to asp.net stil learning...here my
problem....i hav a webform...with 5 textbox's and a
datagrid...and a button...what i wana do is,when i
press the button the values entered in the textbox, i
wana insert  them into the grid...

 
Answer #6    Answered By: Faiza Mian     Answered On: Oct 31

If u are using a database and want to save this into the database and
then display, just submitting the values page and updating the database
will help.

If u don't want to save into the database immediately then after
submitting the page , you must be having a dataset that has been binded
to the datagrid  , so you will require to add a row  in the datatable of
the dataset, and as the dataset is bound to a data grid the values will
be displayed in the datagrid.

 
Answer #7    Answered By: Felix Gray     Answered On: Oct 31

but i tried tht...it works the only
problem is tht i hav initialized the datagrid  with
some columes and 2 columes with chheckbox and
radio...the dataset is adding seperate columns to the
grid...

 
Answer #8    Answered By: Sultana Tabassum     Answered On: Oct 31

how can we dynamically add columns to the datagrid
and aslo how can we make it to store temporary data
from webform

 
Answer #9    Answered By: Hollie Hughes     Answered On: Oct 31

www.learnasp.com/.../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.

 
Answer #10    Answered By: Jackson Williams     Answered On: Oct 31

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>

 
Answer #11    Answered By: Ethan Evans     Answered On: Oct 31

i am using asp.net 2003 and vb.net
i have one dropdownlist
in which i am showing different products

different products has different sizes and different colors
when i choose product from dropdonlist
details of product shows in datagrid
i need to create matrix using datagrid  in which rows will be depend upon color
and sizes
like
color/size Small Medium Large
Blue 50 25 5
White 10 28 18
Green 15 10 5
50,25,5, 10 etc are qty of that products
like product in small size and blue color are in 50 qty
how can i change the matrix depend upon products color and size ?
second problem is
cells of qty must be editable
user should be able to edit any cell
and put qty of that color and size combination

and i want only one update button
by pressing this button
all the values of qty of color and size must be update

 
Didn't find what you were looking for? Find more on datagrid Or get search suggestion and latest updates.




Tagged: