How to add Multiple records associated with a single record in gridview?

Posted by Laghaterohan under Regular Expressions on 12/14/2010 | Points: 10 | Views : 1976 | Status : [Member] | Replies : 4
Hello Friends,

I have following columns in my gridview:

ROLL NO NAME SUBJECTS ASSIGNED
1 XYZ ddl containing subj names(list will be populated here thru db) besides this column i am having ' +' sign.
when the user clicks on '+" the subjects will be added one below the other for ROLL NO 1.
Same logic for all the students..


MAY I KNOW HOW CAN WE DO THIS?? IS THERE ANY SIMPLER WAY??


THANKS!!

Best Regards,
Rohan Laghate



Responses

Posted by: T.saravanan on: 12/14/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Rohan Laghate,

Using JavaScript function you can achieve your output.Try the following way...
First add One Column in your gridview for which one is parent and which one is chid..
In GridViewRowDataBound add (or) call the script using GridViewRow object.


if(e.Row.RowType == DataControlRowType.DataRow)
{
GridViewRow gvr = (GridViewRow)e.Row;
DataRowView drv = (DataRowView)e.Row.DataItem;
string sChild = string.Empty;
if(drv["Parent"].ToString() == "true")
{
// to pass the parent id to get related Child Id's
// Add that child id's into the string.
Ex: sChild = "A,B,C,D,E";
gvr.Attributes.Add("onClick","javascript:Expand(\""+sChild+"\",this)");
}
else
{
// gvr.Attributes.Add("id","Ch_A"); // For A
// gvr.Attributes.Add("id","Ch_B"); // For B
// Using Loop Concept you can add child value into this attributes
}
}


Following is JavaScript..


function Expand(ids, sender)
{
ChildId = ids.split(',');
ID = document.getElementsByName(ids);
var sdata = sender;
var sParData = sData.innerHTML;
for(x=0; x<ChildId.length; x++)
{
if(ChildId[x] != "")
{
objRow = document.getElementById("Ch_"+ChildId[x]);
if(objRow.style.display == "block" || objRow.style.display == '' || objRow.style.display == "table-row" )
{
objRow.style.display = "none";
}
else
{
try
{
objRow.style.display = "table-row"; // If Browser is FireFox
}
catch(ex)
{
objRow.style.display = "block"; // If Browser is IE
}
}
}
}

if(sParData.indexOf("+") > 0)
{
sdata.innerHTML = sdata.innerHTML.replace("+", "-");
}
else if(sParData.indexOf("-") > 0)
{
sdata.innerHTML = sdata.innerHTML.replace("-", "+");
}
}


Just refer this code for your guidance and then try your self...

Cheers :)

Thanks,
T.Saravanan

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Laghaterohan on: 12/14/2010 [Member] Starter | Points: 25

Up
0
Down
Thanks but...still i am unable to implement it...:(


Best Regards,
Rohan Laghate

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Laghaterohan on: 12/14/2010 [Member] Starter | Points: 25

Up
0
Down
Any idea how can we do by server side coding?
Using Templates or ListView control?? please help...its very urgent...

ROLL NAME SUBJECT
1 ABC MATHS +
ENGLISH +
GERMAN

SAVE

THEN WHEN I CLICK ON SAVE ALL THESE DETAILS SHOULD BE SAVED IN DATABASE. I AM CONCERNED ABOUT HOW WILL I GET MY SUBJECTS ONE BELOW THE OTHER WHEN I CLICK ON +

PLEASE HELP

Best Regards,
Rohan Laghate

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 12/15/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Rohan,

what do you try in your side and why you goto server side coding?
Can you show your coding here?



Thanks,
T.Saravanan

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response