I have code to display substring on grid view

public void getData()
{
    SqlConnection conn = new SqlConnection(@"Data Source=DESKTOP-R8LG380\SQLEXPRESS;Initial Catalog=PHIM;Integrated Security=True");
    string query = "SELECT p.MaPhim,TenPhim,TenTA,SoTap,MaQG,MaDD,DSTL = STUFF((SELECT ', ' + tl.TenTL FROM TheLoai AS tl INNER JOIN ChiTietTL AS cttl ON tl.MaTL = cttl.MaTL WHERE cttl.MaPhim = p.MaPhim FOR XML PATH(''), TYPE).value('.[1]','nvarchar(max)'), 1, 2, ''),DSDV = STUFF((SELECT ', ' + dv.TenDV FROM DienVien AS dv INNER JOIN ChiTietDV AS ctdv ON dv.MaDV = ctdv.MaDV WHERE ctdv.MaPhim = p.MaPhim FOR XML PATH(''), TYPE).value('.[1]','nvarchar(max)'), 1, 2, ''), DSTag = STUFF((SELECT ', ' + tag.Tag  FROM TheTag AS tag INNER JOIN ChiTietTag AS cttag ON tag.MaTag = cttag.MaTag WHERE cttag.MaPhim = p.MaPhim FOR XML PATH(''), TYPE).value('.[1]','nvarchar(max)'), 1, 2, ''),NamSX,NgayCongChieu,ChatLuong,TrangThai,NoiDung,ThoiLuong,TongLuotXem,Avatar FROM Phim AS p WHERE p.MaPhim = '"+txtMaPhim.Text+"' ORDER BY p.MaPhim";
    SqlCommand cmd = new SqlCommand(query, conn);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds, "NoiDung");
    dgvNoiDung.DataSource = ds.Tables["NoiDung"];
    dgvNoiDung.DataBind();
}

I want to display DSTL, DSDV, DSTag on listbox with SelectionMode="Multiple"

enter image description here

So hope!

0 Answers