Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Here is my anchor tag which is in gridview. i need to display only that column which has data

Data


this is my function which is used to show pop up bind the data to pop up.


function getData(obj) {

var spl = obj.id.split('_');
var id = spl[1];

if (!isNullOrEmpty(id)) {
$.ajax({
url: "DataFiles.aspx/Description",
type: 'POST',
contentType: 'application/json;charset=utf-8',
datatype: 'json',
data: "{id:" + id + "}",

success: function (data) {


$('#DesPopUp').modal('show');
$('#listOfNotes').html('');
var divContent = '';
divContent += '
';
divContent += '';
//divContent += '';
divContent += '';
divContent += '';

var i = 0;
$.each(data.d, function (key, val) {

i++;
divContent += '';
//divContent += '
1.
';
divContent += '';
//divContent += '';
divContent += '';
divContent += '';
divContent += '';

});
divContent += '
DateTimeEventDescription
' + i + ' ' + val["Date"] + ' ' + val["Time"] + ' ' + val["Event"] + ' ' + val["Description"] + '
';
$('#listOfNotes').append(divContent);



},
error: function (data) {
//
}

});



}
}





function isNullOrEmpty(str) {
if (str != null && str != '')
return false;
else
return true;
}

What I have tried:

requirement is to show only that column which has data , if no then hide that column in the grid.the id which i am passing to anchor tag is the key, if that id has data
in the database it wil bind to div else it wil be empty
now how to show grid column which has data hidde that column which doesnt have..


[WebMethod]
public static List<diarynotes> Description(string id)
{

using (var conn = new SqlConnection(PageBase.ConString))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "SP_GetData";
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.AddWithValue("@Id", id);
var dt = new DataTable();
dt.Load(cmd.ExecuteReader());

List<diarynotes> list = new List<diarynotes>();
try
{
foreach (DataRow row in dt.Rows)
{
DataNote dn = new DataNote();
dn.DataNoteDate = row["DataNoteDate"].ToString();
// dn.DataNoteTime = row["DataNoteTime"].ToString();
dn.Event = row["Event"].ToString();
dn.Description = row["Description"].ToString();
list.Add(dn);
}
}
catch (Exception)
{
throw;
}
return list;


}
}
please help ??
Posted
Updated 5-May-17 0:25am

1 solution

From the stored procedure you can create the anchor tag those has data and only bind that column in grid.


Ex:

SELECT

	CASE
		WHEN columnName IS NOT NULL THEN '<a href=''#'' onclick =''JqryMethod(''' + convert(varchar(20),columnName) + ''');'' />'
		ELSE NULL
	END AS columnName
FROM TableName



Try this it may help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900