Can we group the data in asp repeater in asp webform

sriram0212

Member
Joined
Jun 20, 2020
Messages
8
Programming Experience
1-3
can we able to group a single column in a asp repeater,I need to group phonemumber column where the same phonemumber is displayed in each row, so I need to group the phonemumber alone code:
PhoneNumber
<# DataBinder.Eval(Container.DataItem, "PhoneNumber")>
VOIPUsernameVOIPPasswordSIPProxySIPRegistrarSIPURI
<# DataBinder.Eval(Container.DataItem, "VOIPUsername")><# DataBinder.Eval(Container.DataItem, "VOIPPassword")><# DataBinder.Eval(Container.DataItem, "SIPProxy")><# DataBinder.Eval(Container.DataItem, "SIPRegistrar")><# DataBinder.Eval(Container.DataItem, "SIPURI")>
PhoneNumber
<# DataBinder.Eval(Container.DataItem, "PhoneNumber")>
VOIPUsernameVOIPPasswordSIPProxySIPRegistrarSIPURI
<# DataBinder.Eval(Container.DataItem, "VOIPUsername")>
 
Not at the UI (e.g. Asp Repeater level). You should do the grouping from within your model or view model.
 
Not at the UI (e.g. Asp Repeater level). You should do the grouping from within your model or view model.


If that's the case where can make a change here:
C#:
OrderVOIP message;
                    List<OrderVOIP> messages = new List<OrderVOIP>();

                    OracleConnection conn = null;
                    conn = new OracleConnection(ConfigurationManager.AppSettings["NHibernateOverride.connection.connection_string"]);
                    conn.Open();
                    OracleCommand cmd1 = conn.CreateCommand();
                    cmd1.Connection = conn;
                    cmd1.CommandText = "Select PHONENUMBER,VOIP_USERNAME,VOIP_PASSWORD,SIP_PROXY,SIP_REGISTRAR,SIP_URI,NEW_PHONENUMBER,PHONENUMBER_STATUS from  EDGE_OMNIA.ORDER_VOIP where salesorderid=:salesorderid ORDER BY ID DESC";
                    cmd1.CommandType = CommandType.Text;
                    cmd1.Parameters.Add("salesorderid", salesOrderId);
                    //cmd1.Parameters.Add("phonenumber", phonenumber);
                    cmd1.ExecuteNonQuery();

                    OracleDataReader dr1 = null;
                    dr1 = cmd1.ExecuteReader();

                    while (dr1.Read())
                    {
                        message = new OrderVOIP();
                        string id = dr1[0].ToString();
                        message.PhoneNumber = dr1[0].ToString();
                        message.VOIPUsername = dr1[1].ToString();
                        message.VOIPPassword = dr1[2].ToString();
                        message.SIPProxy = dr1[3].ToString();
                        message.SIPRegistrar = dr1[4].ToString();
                        message.SIPURI = dr1[5].ToString();
                       
                        message.New_PhoneNumber = dr1[6].ToString();
                        message.PhoneNumberStatus = dr1[7].ToString();
                        if(message.PhoneNumberStatus == "RENUMBER")
                        {
                            message.PhoneNumber = message.New_PhoneNumber;
                        }
                        messages.Add(message);

                }
                    dr1.Close();
                    conn.Close();
                    if (messages.Count > 0)
                    {
                        RepviewVOIPDetails.DataSource = messages;
                        RepviewVOIPDetails.DataBind();

                    }
                }
                catch (OracleException ex)
                {
  
                }
            }
        }
 
Last edited by a moderator:
Please put your code in code tags in the future. I did that for you... Or at least as much as I could on my phone.
 
Is there any particular reason why you are using WebForms and straight on ADO.NET? Just want to make sure that you have LINQ available for you to use it needed.
 
Is there any particular reason why you are using WebForms and straight on ADO.NET? Just want to make sure that you have LINQ available for you to use it needed.


I need to use any loop for the phonenumber by saving it in a buffer so I can display & merge the duplicate phonenumber can we do that?!
 
That still doesn't answer for why you you chose to use WebForms and ADO.NET instead of using MVC or SPA with somekind of ORM or Repository pattern.

But to answer your questing about collecting stuff into a buffer and merging them, of course you can do that. The reason why I was asking about LINQ was that you could use out of the box LINQ to do the grouping for you, or you could do it yourself without using LINQ.

But using LINQ requires that you be running at .NET 3.5 or higher. If you are using WebForms and ADO.NET because you are forced to use an older version of the .NET Framework, then you'll definitely have to do things yourself.
 
That still doesn't answer for why you you chose to use WebForms and ADO.NET instead of using MVC or SPA with somekind of ORM or Repository pattern.

But to answer your questing about collecting stuff into a buffer and merging them, of course you can do that. The reason why I was asking about LINQ was that you could use out of the box LINQ to do the grouping for you, or you could do it yourself without using LINQ.

But using LINQ requires that you be running at .NET 3.5 or higher. If you are using WebForms and ADO.NET because you are forced to use an older version of the .NET Framework, then you'll definitely have to do things yourself.


Yes I need to stick to this because it is a huge application, if I recreate something up it will effect the other dependencies, so is there is any idea coming up, I will definitely try it out
 
Well here's a rough outline of what you need to do.
Step 1: Change your SQL query to have it use GROUP BY so that your ADO.NET query gives you back the data already grouped by the phone number. (You'll still want the phone number as part of the selected columns, though.)

Step 2: You'll want to create a class that looks something like:
C#:
class PhoneNumberGroup
{
    public string PhoneNumber { get; set; }
    public IEnumerable<OrderVOIP> Orders { get; set; }
}

Step 3: You'll need to structure your reads from the OracleDataReader to something like this pseudo-code:
C#:
groups = new List<PhoneNumberGroup>();
group = null;
while (reader.Next())
{
    if (group == null || reader["PhoneNumber"] != group.PhoneNumber)
    {
        group = new PhoneNumberGroup();
        group.PhoneNumber = reader["PhoneNumber"];
        group.Orders = new List<OrderVOIP>();
        groups.Add(group);
    }

    // your code to populate an OrderVOIP here.

    group.Add(orderVOIP);
}

Step 4: Pass on that groups list unto the repeater.

Step 5: Set things up on the UI so that you have two repeaters. The general structure should look something like:
C#:
Repeater that iterates over the groups list
<table>
    for each group found render:
    <tr>
        <td>
            <h2>bind to group.PhoneNumber</h2>
            Repeater that iterates over group.Orders list
            <table>
                foreach order found render:
                <tr>
                    <td>bind to order.UserName</td>
                    <td>bind to order.Password</td>
                    :
                </tr>
            </table>
        </td>
    </tr>
</table>

I hope that give you a general idea.
 
Back
Top Bottom