Getting column data from GridView on page using MasterPage
-
Hi, Im having problems getting the value from a column in my GridView. I Have tried all of the following methods and a few others but none return the value and most just give Object not found errors.
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) {//test message ShowMessageBox("CHANGING"); //Label temp=null; //temp.Text = (GridView1.FindControl(Label1.Text)).ToString(); //Label11.Text = GridView1.FindControl(Label1.Text).ToString(); //Label11.Text = GridView1.SelectedDataKey.Value.ToString(); //Label11.Text = GridView1.UniqueID.ToString(); //Label11.Text = GridView1.SelectedDataKey.Values.ToString(); //Label11.Text=GridView1.DataKeys.ToString(); //Label11.Text=GridView1.SelectedRow.Cells[0].Text; }
Any help would be great. Im wondering if the problem is anything to do with the fact im using a masterpage for the template of the actual page im working on???? Or is it coz im not doing it the corect way for ASP.Net 2.0 ???? Thank -
Hi, Im having problems getting the value from a column in my GridView. I Have tried all of the following methods and a few others but none return the value and most just give Object not found errors.
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) {//test message ShowMessageBox("CHANGING"); //Label temp=null; //temp.Text = (GridView1.FindControl(Label1.Text)).ToString(); //Label11.Text = GridView1.FindControl(Label1.Text).ToString(); //Label11.Text = GridView1.SelectedDataKey.Value.ToString(); //Label11.Text = GridView1.UniqueID.ToString(); //Label11.Text = GridView1.SelectedDataKey.Values.ToString(); //Label11.Text=GridView1.DataKeys.ToString(); //Label11.Text=GridView1.SelectedRow.Cells[0].Text; }
Any help would be great. Im wondering if the problem is anything to do with the fact im using a masterpage for the template of the actual page im working on???? Or is it coz im not doing it the corect way for ASP.Net 2.0 ???? ThankIs ShowMessageBox("CHANGING"); a method or have you confused it with console app?
Nila "...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea
-
Is ShowMessageBox("CHANGING"); a method or have you confused it with console app?
Nila "...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea
Hi SHOWMESSAGEBOX is a method for displaying a pop-up. I use it just to confirm the action of the button click has occurred. This has nothing to do with the error / problem im getting.
-
Hi, Im having problems getting the value from a column in my GridView. I Have tried all of the following methods and a few others but none return the value and most just give Object not found errors.
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) {//test message ShowMessageBox("CHANGING"); //Label temp=null; //temp.Text = (GridView1.FindControl(Label1.Text)).ToString(); //Label11.Text = GridView1.FindControl(Label1.Text).ToString(); //Label11.Text = GridView1.SelectedDataKey.Value.ToString(); //Label11.Text = GridView1.UniqueID.ToString(); //Label11.Text = GridView1.SelectedDataKey.Values.ToString(); //Label11.Text=GridView1.DataKeys.ToString(); //Label11.Text=GridView1.SelectedRow.Cells[0].Text; }
Any help would be great. Im wondering if the problem is anything to do with the fact im using a masterpage for the template of the actual page im working on???? Or is it coz im not doing it the corect way for ASP.Net 2.0 ???? ThankSorry 'bout the earlier smartie-pants comment ;) Do this: create a control at runtime to match your Gridview's templated control Label lbl = GridView1.FindControl(Label1); _yourVariable = lbl.text; Also I would imagine you gotta do this for the Label1 control appearing on EACH row... do you know how to do that?
Nila "...for that, I will need a large cup of coffee and a bran muffin!" -Samantha Bea
-
Sorry 'bout the earlier smartie-pants comment ;) Do this: create a control at runtime to match your Gridview's templated control Label lbl = GridView1.FindControl(Label1); _yourVariable = lbl.text; Also I would imagine you gotta do this for the Label1 control appearing on EACH row... do you know how to do that?
Nila "...for that, I will need a large cup of coffee and a bran muffin!" -Samantha Bea
Grapes-R-Fun wrote:
Do this: create a control at runtime to match your Gridview's templated control Label lbl = GridView1.FindControl(Label1); _yourVariable = lbl.text; Also I would imagine you gotta do this for the Label1 control appearing on EACH row... do you know how to do that?
Nila, dont worry i didnt take the comment as bad. Let me re-iterate what im trying to do, just to clarify we are thinking along the same lines. Ok, i have a gridview displaying data, when i click the select button on a given row i need to get the value of the data (unique_id) displayed in the first column. This column is also the DataKey for the gridview. So how can i get this info? Ive tried all sorts but to no avail. What would you suggest and how would you implement it? Sorry if this seems like im asking you to tell me how to do it all, but ive tried that many ways that should work and dont, that i really would appreciate it if you could explain in as much detail as possible. I dont know if this makes any difference but i am using MasterPage for the template of the page. I read somewhere that you have to drill right down to the control if using MasterPages. Is this true, and does it apply in this instance? If what you said above is still true
Label lbl = GridView1.FindControl(Label1); _yourVariable = lbl.text;
Then how would you implement this? At present ive tried both SelectedIndexChanged / SelectedIndexChanging, but without success. I get the error that the Object Referenced does not exist. This happenes no matter if i try indexing the column or the Label1 control used to display the info in the required column. So again, id be really greatful if you could tell me how you would approach it, in all its horrible detail :zzz::->:omg: Thanks!!!!!!! -
Grapes-R-Fun wrote:
Do this: create a control at runtime to match your Gridview's templated control Label lbl = GridView1.FindControl(Label1); _yourVariable = lbl.text; Also I would imagine you gotta do this for the Label1 control appearing on EACH row... do you know how to do that?
Nila, dont worry i didnt take the comment as bad. Let me re-iterate what im trying to do, just to clarify we are thinking along the same lines. Ok, i have a gridview displaying data, when i click the select button on a given row i need to get the value of the data (unique_id) displayed in the first column. This column is also the DataKey for the gridview. So how can i get this info? Ive tried all sorts but to no avail. What would you suggest and how would you implement it? Sorry if this seems like im asking you to tell me how to do it all, but ive tried that many ways that should work and dont, that i really would appreciate it if you could explain in as much detail as possible. I dont know if this makes any difference but i am using MasterPage for the template of the page. I read somewhere that you have to drill right down to the control if using MasterPages. Is this true, and does it apply in this instance? If what you said above is still true
Label lbl = GridView1.FindControl(Label1); _yourVariable = lbl.text;
Then how would you implement this? At present ive tried both SelectedIndexChanged / SelectedIndexChanging, but without success. I get the error that the Object Referenced does not exist. This happenes no matter if i try indexing the column or the Label1 control used to display the info in the required column. So again, id be really greatful if you could tell me how you would approach it, in all its horrible detail :zzz::->:omg: Thanks!!!!!!!Nah, the Masterpage has nothing to do with this... just convert all your columns to templates (note that they will all default to Label controls; let me know if you need help with templated fields), then give your templated controls meaningful names. THEN you can access them like this: String _city; ... protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { ... Label city = (Label)(GridView1.SelectedRow.FindControl("cityLabel")); _city = city.Text; city.Dispose(); //yup, always clean up! TextBox copy = (TextBox)(GridView1.SelectedRow.FindControl("copyTextBox")); copy.Text = _city copy.Dispose(); } Give this a try. Let me know if it works ro not :-)
Nila "...for that, I will need a large cup of coffee and a bran muffin!" -Samantha Bea
-
Nah, the Masterpage has nothing to do with this... just convert all your columns to templates (note that they will all default to Label controls; let me know if you need help with templated fields), then give your templated controls meaningful names. THEN you can access them like this: String _city; ... protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { ... Label city = (Label)(GridView1.SelectedRow.FindControl("cityLabel")); _city = city.Text; city.Dispose(); //yup, always clean up! TextBox copy = (TextBox)(GridView1.SelectedRow.FindControl("copyTextBox")); copy.Text = _city copy.Dispose(); } Give this a try. Let me know if it works ro not :-)
Nila "...for that, I will need a large cup of coffee and a bran muffin!" -Samantha Bea
Thanks Nila, Ill give it a try today, and ill let you know how it goes! ;-)
-
Nah, the Masterpage has nothing to do with this... just convert all your columns to templates (note that they will all default to Label controls; let me know if you need help with templated fields), then give your templated controls meaningful names. THEN you can access them like this: String _city; ... protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { ... Label city = (Label)(GridView1.SelectedRow.FindControl("cityLabel")); _city = city.Text; city.Dispose(); //yup, always clean up! TextBox copy = (TextBox)(GridView1.SelectedRow.FindControl("copyTextBox")); copy.Text = _city copy.Dispose(); } Give this a try. Let me know if it works ro not :-)
Nila "...for that, I will need a large cup of coffee and a bran muffin!" -Samantha Bea
Mate I Loves Ya! That works perfectly!!! Thanks a lot. But perhaps you can tell me 1 thing? Why does it only work when passing the Controls Data to a variable and then onto the static label control, yet it doesnt work when i miss out the middle man and try getting the data from the dynamic label and adding it straight to the static label? Thanks again. I appreciate your time!
-
Mate I Loves Ya! That works perfectly!!! Thanks a lot. But perhaps you can tell me 1 thing? Why does it only work when passing the Controls Data to a variable and then onto the static label control, yet it doesnt work when i miss out the middle man and try getting the data from the dynamic label and adding it straight to the static label? Thanks again. I appreciate your time!
Oh I have no idea why... typically when something doesn't work, I find a work around and move-on. Im sure the 'corky' .Net has its reasons, I just don't have time/patience to figure out the WHY ;-) Now, what does Mate I Loves Ya! mean??
Nila "...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea
-
Oh I have no idea why... typically when something doesn't work, I find a work around and move-on. Im sure the 'corky' .Net has its reasons, I just don't have time/patience to figure out the WHY ;-) Now, what does Mate I Loves Ya! mean??
Nila "...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea
Grapes-R-Fun wrote:
Now, what does Mate I Loves Ya! mean??
Ive no idea. Its a work around i use on my Girlfriend for most situations
Babe, i love you!
Likewise i dont understand women or what they want. lol!! :confused::laugh: -
Grapes-R-Fun wrote:
Now, what does Mate I Loves Ya! mean??
Ive no idea. Its a work around i use on my Girlfriend for most situations
Babe, i love you!
Likewise i dont understand women or what they want. lol!! :confused::laugh:LOL- are u flirting with me? :-O
Nila "...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea
-
LOL- are u flirting with me? :-O
Nila "...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea
Grapes-R-Fun wrote:
are u flirting with me?
I wasnt until i saw your pic on your profile!:->
-
Grapes-R-Fun wrote:
are u flirting with me?
I wasnt until i saw your pic on your profile!:->
um, how did you see my pic? do you have one??;)
Nila "...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea
-
um, how did you see my pic? do you have one??;)
Nila "...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea
Your profile!
-
Your profile!
oh yeah, I figured how to see others' profiles as well... I am queen of the clueless nation!! why don't you put your pic up?
Nila "...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea
-
oh yeah, I figured how to see others' profiles as well... I am queen of the clueless nation!! why don't you put your pic up?
Nila "...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea
Grapes-R-Fun wrote:
why don't you put your pic up?
Are you flirting with me?
-
Grapes-R-Fun wrote:
why don't you put your pic up?
Are you flirting with me?
lol, maybe!
Nila I do ANYTHING for an extra large cup of coffee!