如何在列表视图中显示与表字段中的分号分隔的ID [英] how to display semicolumn separated ids from table field in listview

查看:76
本文介绍了如何在列表视图中显示与表字段中的分号分隔的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

专家,

我今天是Satardekar,


recent_campaign.aspx 页中,我正在显示 crm_campaign表
中的最新广告系列
crm_campaign表包含诸如所有者,状态,开始日期,结束日期,事件ID 等字段.

event_ids 包含从crm_events表分配给带有半列分隔符的Perticuler广告系列的事件ID .像1,2,7

现在我想在列表视图中显示所有信息

listview绑定代码-

Hi Expert,

I am uday Satardekar,


In recent_campaign.aspx page i am showing recent campaigns from crm_campaign table

crm_campaign table contains fields like owner,status,start_date,end_date,event_ids etc.

event_ids contains event ids assigned from crm_events table to perticuler campaigns with semi column separate. like 1,2,7

Now i want to show this all information in listview

listview binding code-

string connectStr = ConfigurationManager.ConnectionStrings["ExpoCrmConnectionString"].ToString();
           connect = new MySqlConnection(connectStr);
           connect.Open();

           string strQueryRecentCampaign = "SELECT  cmp.campaign_id,log.name,cmp.campaign_name,cmp.campaign_status,cmp.event_ids,cmp.campaign_type,campaign_data_status_ids,cmp.start_date,cmp.end_date,cat.category,num_sent,budgeted_cost FROM crm_campaign cmp INNER JOIN crm_login log ON cmp.campaign_owner=log.log_id INNER JOIN crm_category cat ON cmp.cat_id=cat.cat_id";
           MySqlCommand command = new MySqlCommand(strQueryRecentCampaign, connect);
           MySqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
           DataTable dt = new DataTable();
           dt.Load(reader);
           listvwRecentCampaign.DataSource = dt;
           listvwRecentCampaign.DataBind();
           connect.Close();



我的itentemplate就像-




And My itentemplate is like -


<td ><%# Eval("name")%></td>
                                      <td><%# Eval("campaign_name")%></td>
                                      <td><%# Eval("campaign_status")%></td>
                                       <td><%# Eval("campaign_type")%></td>

                                       <td><%# Eval("start_date", "{0:dd-MM-yyyy}")%>
                      <asp:Label ID="lbEventID" runat="server"
      Text=''<%# Eval("campaign_id") %>'' Visible="false" />
     <asp:Label ID="CompanycodeLabel" runat="server"
      Text=''<%# Eval("campaign_id") %>'' Visible="False" />
                      </td>
                      <td><%# Eval("end_date", "{0:dd-MM-yyyy}") ?? "&nbsp;"%></td>
                      <td><%# Eval("num_sent")%></td>
                    <table><tbody><tr><td><%# Eval("event_ids")%></td></tr></tbody></table>
                      <td><%# Eval("category")%></td>
                                        <td>




下面的行仅在列表视图中显示带有半列的ID.




Below line shows only ids with semi column as result in listview.

<td><%# Eval("campaign_type")%></td>



我如何以及在何处分隔这些ID,以及如何在列表视图中显示与这些ID相关的事件名称作为结果.

在此先感谢....



How and where i separate these ids and how i can show event name associated with these ids in listview as results.

Thanks in advance................

推荐答案

在行数据绑定事件中,您可以获取每排都像1,2表示第一行,3,4,5表示第二行,等等.

现在,在同一事件上,您可以通过在查询中使用IN子句触发查询并获取与逗号分隔的ID关联的事件名称,并返回结果,您可以将其绑定到在列表视图中获取的控件.

如果您能理解我的意思,请告诉我.

-Prashant
On row data bound event you can get the id''s of each row like 1,2 for first row , 3,4,5 for second row etc.

Now on same event you can fire query and get the event name associated with comma separated id''s by using IN clause in query and returning result you can bind to the control you have taken in list view.

Please let me know if you able to understand what i am saying.

-Prashant


最后我得到了解决方案,

我将以下代码放在itemDataBound事件上.在列表视图中,我对所有事件名称使用了一个标签控件.

Finally i got solution ,

I put following code on itemDataBound event.and in listview i took one label control for all events name.

if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            ListViewDataItem item = (ListViewDataItem)e.Item;
            Label lblEvents = (Label)e.Item.FindControl("events");

            DataRowView drvItemIds = (DataRowView)item.DataItem;
            string strItemIds = drvItemIds["event_ids"].ToString();

            string strItemIds1 = strItemIds.Insert(0, "(");
            string strItemIds2 = strItemIds1.Insert(strItemIds1.Length, ")");

            string[] strArrItemIds = strItemIds.Split(',');

            MySqlConnection connect = null;

            try
            {

                string connectStr = ConfigurationManager.ConnectionStrings["ExpoCrmConnectionString"].ToString();
                connect = new MySqlConnection(connectStr);
                connect.Open();

                string strQueryRecentCampaign = "SELECT event_name from crm_event where event_id IN (" + strItemIds + ") ";
                MySqlCommand command = new MySqlCommand(strQueryRecentCampaign, connect);
                MySqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                DataTable dt = new DataTable();
                dt.Load(reader);

                int numberOfEvents = dt.Rows.Count;
                lblEvents.Text = "";
                string eventsName="";
                for (int i = 0; i < numberOfEvents; i++)
                {
                    eventsName = eventsName + ", " + dt.Rows[i][0].ToString();
                    
                }
                string evntsNm= eventsName.Remove(0, 1);
                lblEvents.Text = evntsNm;
                connect.Close();
            }
            catch (Exception ex)
            {

            }
            finally
            {
                connect.Close();
            }
           
        }


这篇关于如何在列表视图中显示与表字段中的分号分隔的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆