Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
Per Salmi #1
Presenting records over multiple rows?
I wonder if it is easy to use the DataGrid to display for example 4 data
values related to a record on one grid-row and then have a 5th grid-row
spanning all 4 columns that displays the 5th data value?
This would then repeat for each record in the datatable showing each record
on 2 rows. The first row with a few short data values and the second row
showing a long text string.
Or would it be better to build this with a repeater instead of the DataGrid?
/Per
Per Salmi Guest
-
Multiple rows of data into 1 row
I have a Pt ID field which is a unique number. I have a S_field which is an ID # that lines to the Pt ID. There are multiple Pt ID's for one... -
Inserting Multiple Rows
Is it possible to insert a number of rows into a table based on a value entered in a textbox? For example (I'm a tech writer not a... -
CF Multiple Queries, Multiple Records
All, I've got three queries all passing variables from previous queries. The issues? The second query returns 4 records. I want to use IDs for... -
update multiple records in multiple tables from one form
hello I have been trying to run multiple update queries based on the data entered by user. Brief background: I am fetching data from various... -
Adding blank rows after a series of records
On Wed, 23 Jul 2003 14:04:49 -0700, "Chuck Dickson" <CDICKSO@USAIRWAYS.COM> wrote: That would be pretty tough. The only way I can think to do... -
Jeffrey Tan[MSFT] #2
RE: Presenting records over multiple rows?
Hi Per,
Thank you for posting in the community!
Based on my understanding, you want to show your each record in 2 rows:
first row contains 4 fields, while the second row contains the 5th field
record, which spans the whole row's length.
================================================
The datagrid control ¨¬s a highly tailored control, which will render one
record in one row.
Based on my experience, Repeater control gives your more control on
databinding render. You may use Repeater control to render one record as 2
rows.
I have used Sql Server's default "jobs" table in "pubs" database to write a
sample project for you:
Html view code:
<asp:repeater id="Repeater1" runat="server">
<HeaderTemplate>
<table align="center" border="1">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td runat="server" id="job_id" align="center"><%#
DataBinder.Eval(Container.DataItem,"job_id")%></td>
<td runat="server" id="min_lvl" align="center"><%#
DataBinder.Eval(Container.DataItem,"min_lvl")%></td>
<td runat="server" id="max_lvl" align="center"><%#
DataBinder.Eval(Container.DataItem,"max_lvl")%></td>
</tr>
<tr>
<td runat="server" id="job_desc" align="center" colspan="3"><%#
DataBinder.Eval(Container.DataItem,"job_desc")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:repeater>
Code behind:
private void Page_Load(object sender, System.EventArgs e)
{
SqlDataAdapter adapter=new SqlDataAdapter("select * from
jobs","server=localhost;database=pubs;uid=sa;pwd=" );
DataSet ds=new DataSet();
adapter.Fill(ds);
Repeater1.DataSource=ds.Tables[0];
Repeater1.DataBind();
}
In the code, for each <ItemTemplate>, I use 2 rows, first with 3 <td>s,
while second with 1 <td>. I add the attribute colspan=3, which makes this
<td> span 3 <td> length(The whole <tr>)
=================================================
Please apply my suggestion above and let me know if it helps resolve your
problem.
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - [url]www.microsoft.com/security[/url]
This posting is provided "as is" with no warranties and confers no rights.
Jeffrey Tan[MSFT] Guest
-
Per Salmi #3
Re: Presenting records over multiple rows?
Thanks for the solution, I tested it and it was exactly the thing I was
looking for.
I also managed to do the same thing with a DataGrid. That was possible by
implementing a handler for the ItemDataBound event where I create a
DataGridItem with a TableCell using the ColSpan property, setting the Text
property of the TableCell and finally adding the DataGridItem to the
Controls collection of the DataGrid.
Best regards,
Per Salmi
""Jeffrey Tan[MSFT]"" <v-jetan@online.microsoft.com> skrev i meddelandet
news:Nv24qc37DHA.3852@cpmsftngxa07.phx.gbl...a>
> Hi Per,
>
> Thank you for posting in the community!
>
> Based on my understanding, you want to show your each record in 2 rows:
> first row contains 4 fields, while the second row contains the 5th field
> record, which spans the whole row's length.
>
> ================================================
> The datagrid control ¨¬s a highly tailored control, which will render one
> record in one row.
> Based on my experience, Repeater control gives your more control on
> databinding render. You may use Repeater control to render one record as 2
> rows.
>
> I have used Sql Server's default "jobs" table in "pubs" database to write> sample project for you:
>
> Html view code:
> <asp:repeater id="Repeater1" runat="server">
> <HeaderTemplate>
> <table align="center" border="1">
> </HeaderTemplate>
> <ItemTemplate>
> <tr>
> <td runat="server" id="job_id" align="center"><%#
> DataBinder.Eval(Container.DataItem,"job_id")%></td>
> <td runat="server" id="min_lvl" align="center"><%#
> DataBinder.Eval(Container.DataItem,"min_lvl")%></td>
> <td runat="server" id="max_lvl" align="center"><%#
> DataBinder.Eval(Container.DataItem,"max_lvl")%></td>
> </tr>
> <tr>
> <td runat="server" id="job_desc" align="center" colspan="3"><%#
> DataBinder.Eval(Container.DataItem,"job_desc")%></td>
> </tr>
> </ItemTemplate>
> <FooterTemplate>
> </table>
> </FooterTemplate>
> </asp:repeater>
>
> Code behind:
> private void Page_Load(object sender, System.EventArgs e)
> {
> SqlDataAdapter adapter=new SqlDataAdapter("select * from
> jobs","server=localhost;database=pubs;uid=sa;pwd=" );
> DataSet ds=new DataSet();
> adapter.Fill(ds);
> Repeater1.DataSource=ds.Tables[0];
> Repeater1.DataBind();
> }
>
> In the code, for each <ItemTemplate>, I use 2 rows, first with 3 <td>s,
> while second with 1 <td>. I add the attribute colspan=3, which makes this
> <td> span 3 <td> length(The whole <tr>)
>
> =================================================
> Please apply my suggestion above and let me know if it helps resolve your
> problem.
>
> Thank you for your patience and cooperation. If you have any questions or
> concerns, please feel free to post it in the group. I am standing by to be
> of assistance.
> Have a nice day!!
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - [url]www.microsoft.com/security[/url]
> This posting is provided "as is" with no warranties and confers no rights.
>
Per Salmi Guest
-
Jeffrey Tan[MSFT] #4
Re: Presenting records over multiple rows?
Hi Per,
Thanks very much for your feedback.
I am glad my reply makes sense to you.
Yes, you also can hook into the ItemDataBound event and add the TableRow
dynamicly. But I think use the Repeater control is a more freely way to
handle this issue.
Anyway, it works :-)
If you have any further concern, please feel free to post, I will help you.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - [url]www.microsoft.com/security[/url]
This posting is provided "as is" with no warranties and confers no rights.
Jeffrey Tan[MSFT] Guest
-
Per Salmi #5
Re: Presenting records over multiple rows?
Ok, now I am back using the Repeater because I need to add checkboxes on a
column for some of the items that I display.
I got this working by adding asp:checkbox tags to the ItemTemplate inside TD
tags.
I also added paging to the repeater with PagedDataSource and now I need to
get the checked rows when the user moves to a new page or clicks a button.
I tried to get the Checked property from the Checkbox controls by using
Repeater1.Items and FindControl("cbMyCheckBox") but the Checked property is
always false no matter if the checkbox was checked or not!
Is it not possible to find out which RepeaterItems were checked by looping
over the Items in the Repeater? Why are they all "unchecked"?
Best regards,
Per Salmi
""Jeffrey Tan[MSFT]"" <v-jetan@online.microsoft.com> skrev i meddelandet
news:JKnB5LI8DHA.2992@cpmsftngxa07.phx.gbl...you.>
> Hi Per,
>
> Thanks very much for your feedback.
>
> I am glad my reply makes sense to you.
>
> Yes, you also can hook into the ItemDataBound event and add the TableRow
> dynamicly. But I think use the Repeater control is a more freely way to
> handle this issue.
>
> Anyway, it works :-)
>
> If you have any further concern, please feel free to post, I will help>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - [url]www.microsoft.com/security[/url]
> This posting is provided "as is" with no warranties and confers no rights.
>
Per Salmi Guest
-
Ben Miller [MSFT]\\ #6
Re: Presenting records over multiple rows?
The key to this may be that ViewState is turned off. Then they will all be
default unchecked.
Ben Miller
Get Secure! - [url]www.microsoft.com/security[/url]
This posting is provided "as is" with no warranties and confers no rights.
"Per Salmi" <per-n0sp4m@n0sp4m-litho.se> wrote in message
news:uI25HvX8DHA.2404@TK2MSFTNGP11.phx.gbl...TD> Ok, now I am back using the Repeater because I need to add checkboxes on a
> column for some of the items that I display.
>
> I got this working by adding asp:checkbox tags to the ItemTemplate insideis> tags.
> I also added paging to the repeater with PagedDataSource and now I need to
> get the checked rows when the user moves to a new page or clicks a button.
>
> I tried to get the Checked property from the Checkbox controls by using
> Repeater1.Items and FindControl("cbMyCheckBox") but the Checked propertyrights.> always false no matter if the checkbox was checked or not!
>
> Is it not possible to find out which RepeaterItems were checked by looping
> over the Items in the Repeater? Why are they all "unchecked"?
>
> Best regards,
> Per Salmi
>
>
> ""Jeffrey Tan[MSFT]"" <v-jetan@online.microsoft.com> skrev i meddelandet
> news:JKnB5LI8DHA.2992@cpmsftngxa07.phx.gbl...> you.> >
> > Hi Per,
> >
> > Thanks very much for your feedback.
> >
> > I am glad my reply makes sense to you.
> >
> > Yes, you also can hook into the ItemDataBound event and add the TableRow
> > dynamicly. But I think use the Repeater control is a more freely way to
> > handle this issue.
> >
> > Anyway, it works :-)
> >
> > If you have any further concern, please feel free to post, I will help> >
> > Best regards,
> > Jeffrey Tan
> > Microsoft Online Partner Support
> > Get Secure! - [url]www.microsoft.com/security[/url]
> > This posting is provided "as is" with no warranties and confers no>> >
>
Ben Miller [MSFT]\\ Guest
-
Jeffrey Tan[MSFT] #7
Re: Presenting records over multiple rows?
Hi Per,
Thanks for posting your further issue.
Based on my understanding, you still use the Repeater control to display
the data, and you add an extra checkbox column for each Repeater Item(In
your situation, every 2 rows), but when you check the CheckBox stats at
server side, you find that they are always unchecked.
===========================================
Actually, I think there are many possibilities for this issue. You need to
post some of your implement code for us to check.
Anyway, I think the likest problem may be that you did not judge the
postback, and always rebind the Repeater control in Page_Load event.
If you always rebind your repeater control to the data, then the whole
status of Repeater control will be refreshed(Initialized), so the
checkbox's checked status will be lost.
Normally, if you only bind at the first load time, then everything will
work well, like this:
Html code:
<asp:repeater id="Repeater1" runat="server">
<HeaderTemplate>
<table align="center" border="1">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align="center"><asp:CheckBox ID="cb"
Runat="server"></asp:CheckBox></td>
<td runat="server" id="job_id" align="center"><%#
DataBinder.Eval(Container.DataItem,"job_id")%></td>
<td runat="server" id="min_lvl" align="center"><%#
DataBinder.Eval(Container.DataItem,"min_lvl")%></td>
<td runat="server" id="max_lvl" align="center"><%#
DataBinder.Eval(Container.DataItem,"max_lvl")%></td>
</tr>
<tr>
<td runat="server" id="job_desc" align="center" colspan="4"><%#
DataBinder.Eval(Container.DataItem,"job_desc")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:repeater>
Then, at the server side:
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
SqlDataAdapter adapter=new SqlDataAdapter("select * from
jobs","server=localhost;database=pubs;uid=sa;pwd=" );
DataSet ds=new DataSet();
adapter.Fill(ds);
Repeater1.DataSource=ds.Tables[0];
Repeater1.DataBind();
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
foreach(RepeaterItem ri in Repeater1.Items)
{
if(ri.ItemType==ListItemType.Item||ri.ItemType==Li stItemType.AlternatingItem
)
{
foreach(Control c in ri.Controls)
{
if(c is CheckBox)
{
CheckBox cb=(CheckBox)c;
if(cb.Checked)
{
this.Response.Write("The "+ ri.ItemIndex.ToString()+"th item is
checked<br>");
}
}
}
}
}
}
Note: I used Sql Server's default "jobs" table in "pubs" database.
==============================================
Please apply my suggestion above and let me know if it helps resolve your
problem.
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - [url]www.microsoft.com/security[/url]
This posting is provided "as is" with no warranties and confers no rights.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - [url]www.microsoft.com/security[/url]
This posting is provided "as is" with no warranties and confers no rights.
Jeffrey Tan[MSFT] Guest
-
Per Salmi #8
Re: Presenting records over multiple rows?
Yes, the problem was that the Repeater databinding was executed before I
tried to find the checked CheckBoxes... Now that is fixed and I find the
checked items. I get the IDs of my database items by providing them in
hidden fields in the repeater and accessing them by the FindControl-method
as I understand that the RepeaterItem.DataItem is not available until
databinding has been established.
So, now it works!
/Per Salmi
""Jeffrey Tan[MSFT]"" <v-jetan@online.microsoft.com> skrev i meddelandet
news:v6G4bbd8DHA.2852@cpmsftngxa07.phx.gbl...if(ri.ItemType==ListItemType.Item||ri.ItemType==Li stItemType.AlternatingItem>
> Hi Per,
>
> Thanks for posting your further issue.
>
> Based on my understanding, you still use the Repeater control to display
> the data, and you add an extra checkbox column for each Repeater Item(In
> your situation, every 2 rows), but when you check the CheckBox stats at
> server side, you find that they are always unchecked.
>
> ===========================================
> Actually, I think there are many possibilities for this issue. You need to
> post some of your implement code for us to check.
>
> Anyway, I think the likest problem may be that you did not judge the
> postback, and always rebind the Repeater control in Page_Load event.
>
> If you always rebind your repeater control to the data, then the whole
> status of Repeater control will be refreshed(Initialized), so the
> checkbox's checked status will be lost.
>
> Normally, if you only bind at the first load time, then everything will
> work well, like this:
>
> Html code:
> <asp:repeater id="Repeater1" runat="server">
> <HeaderTemplate>
> <table align="center" border="1">
> </HeaderTemplate>
> <ItemTemplate>
> <tr>
> <td align="center"><asp:CheckBox ID="cb"
> Runat="server"></asp:CheckBox></td>
> <td runat="server" id="job_id" align="center"><%#
> DataBinder.Eval(Container.DataItem,"job_id")%></td>
> <td runat="server" id="min_lvl" align="center"><%#
> DataBinder.Eval(Container.DataItem,"min_lvl")%></td>
> <td runat="server" id="max_lvl" align="center"><%#
> DataBinder.Eval(Container.DataItem,"max_lvl")%></td>
> </tr>
> <tr>
> <td runat="server" id="job_desc" align="center" colspan="4"><%#
> DataBinder.Eval(Container.DataItem,"job_desc")%></td>
> </tr>
> </ItemTemplate>
> <FooterTemplate>
> </table>
> </FooterTemplate>
> </asp:repeater>
>
> Then, at the server side:
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> if(!IsPostBack)
> {
> SqlDataAdapter adapter=new SqlDataAdapter("select * from
> jobs","server=localhost;database=pubs;uid=sa;pwd=" );
> DataSet ds=new DataSet();
> adapter.Fill(ds);
> Repeater1.DataSource=ds.Tables[0];
> Repeater1.DataBind();
> }
> }
>
> private void Button1_Click(object sender, System.EventArgs e)
> {
> foreach(RepeaterItem ri in Repeater1.Items)
> {
>
>> )
> {
> foreach(Control c in ri.Controls)
> {
> if(c is CheckBox)
> {
> CheckBox cb=(CheckBox)c;
> if(cb.Checked)
> {
> this.Response.Write("The "+ ri.ItemIndex.ToString()+"th item is
> checked<br>");
> }
> }
> }
> }
> }
> }
>
> Note: I used Sql Server's default "jobs" table in "pubs" database.
>
> ==============================================
> Please apply my suggestion above and let me know if it helps resolve your
> problem.
>
> Thank you for your patience and cooperation. If you have any questions or
> concerns, please feel free to post it in the group. I am standing by to be
> of assistance.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - [url]www.microsoft.com/security[/url]
> This posting is provided "as is" with no warranties and confers no rights.
>
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - [url]www.microsoft.com/security[/url]
> This posting is provided "as is" with no warranties and confers no rights.
>
Per Salmi Guest
-
Jeffrey Tan[MSFT] #9
Re: Presenting records over multiple rows?
Hi Per,
Thanks very much for your feedback.
I am glad it works now, if you still have any further concern, please feel
free to tell me, I will help you.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - [url]www.microsoft.com/security[/url]
This posting is provided "as is" with no warranties and confers no rights.
Jeffrey Tan[MSFT] Guest



Reply With Quote

