 |
|
 |
I tried this but it gives me the values in the cell. How to I get the row index so that I can use it to reference on the on the other columns?
Thanks,
|
|
|
|
 |
|
 |
Hi
I have grid view that bind to database which is have ID,dat ,Body ,Status,Title,UserName field I want to have an edit column that when I click on it show a panel in status column that show data in body field to edit this field I think you can help me more. Thanks
|
|
|
|
 |
|
 |
Some times a simple approach is required to get the job done.
|
|
|
|
 |
|
 |
You haven't declared the "Button Control" in your .aspx code
|
|
|
|
 |
|
 |
Hi There
Can you give me a sample method to get the current row index for this example please ?
I can only get an index of -1 when I try this and am not sure if my method is wrong or whether the radio button is returning to the top when the action button I have corrected is pressed ?
Many thanks in advance
Lufty8898
|
|
|
|
 |
|
 |
Agree with Geoffrey Morton-Haworth
|
|
|
|
 |
|
 |
Glosses over the difficulties, did not mention official MS solution...
|
|
|
|
 |
|
 |
Glosses over the difficulties
|
|
|
|
 |
|
 |
The official microsoft solution is better, see http://www.asp.net/learn/data-access/tutorial-51-vb.aspx
This article explains why this is so tricky and how to solve it using a literal controls, which allows you to select a radio button (other than first or last) on page load.
|
|
|
|
 |
|
 |
Hi,
Not sure how it is better than what I have explained in the above code. My code using only one line of code to achieve the results.
Mohammad Azam
azamsharp@gmail.com
www.gridviewguy.com
www.screencastaday.com
Houston, TEXAS
|
|
|
|
 |
|
 |
There are dozens of articles on radio buttons in GridViews, all describing approaches that work to some degree or other.
IMHO the official asp.net code article offers the most complete solution, one which enables you to preselect a radio button (not just the first or last) on page load and also addresses the security issues. But I would agree that the valuable stuff is buried under reams of tedious tick-the-box configuration nonsense, which is far more convoluted than simply writing out the code.
If you are adding radio buttons to GridViews all over the place, another route is Metabuilders DataControlFields SelectorField component (download free from http://www.metabuilders.com/)
|
|
|
|
 |
|
 |
This didn't work for me, the result was, that only one row was shown instead of ...well more.
So I wrote a very Quick'n'Dirty solution in JavaScript:
function checkRadioButtons(id)
{
i = 2;
while (document.getElementById('ctl00$mainContent$dgData$ctl0' + i + '$radDefault') != null)
{
rad = document.getElementById('ctl00$mainContent$dgData$ctl0' + i + '$radDefault');
if (i == id)
{
rad.checked = true;
}
else
{
rad.checked = false;
}
i++;
}
}
You have to alter the function, if there are more than 10 rows, because the "ctl0x" will be a "ctlxx" from the 11th row on...
The javascript call is added in the ItemDataBound-Event of the DataGrid:
...
RadioButton rad = (RadioButton)e.Item.FindControl("radDefault");
...
rad.Attributes.Add("onClick", "javascript:checkRadioButtons('" + workaround_i.ToString() + "')");
workaround_i++;
...
You have to figure out which number the "workaround_i" is starting with, since it is not 0 or 1, but 2 in my case. Just look for the first kind of "name="ctl00$mainContent$dgData$ctl02$radDefault" in your generated HTML code.
Yours,
Smuus
|
|
|
|
 |
|
 |
Does this solution works when the paging is enabled?. Please let me know. Thanks
|
|
|
|
 |
|
 |
At the time of click the button my last checked radio button was cleared how can i handle this problem
sambath
|
|
|
|
 |
|
 |
sir i have a gridview having clientside radiobutton.
i select a radio and opens a new page. after that i return to the first page the selected radio will no longer be selected. i want that the radio i select will remain selected until i select a new one.
i used this in gridview:
<input type="radio" name="rd1" value="<%# Eval("id")%>" checked="checked" />
thanks in advance.
|
|
|
|
 |
|
 |
This article is very good, simple but to the point.
|
|
|
|
 |
|
 |
If you can deal with a postback on each click of the radio - you can use a server control with the code below. It runs in the RadioButton_CheckChanged event, and just UNchecks all the radio buttons that are not the one that was just clicked.
protected void rdoSelect_CheckedChanged(object sender, EventArgs e)
{
foreach (GridViewRow row in dgSearchResults.Rows)
{
RadioButton rdo = (RadioButton)row.FindControl("rdoSelect");
if (rdo != null)
rdo.Checked = (rdo.ClientID.ToString() == ((RadioButton)sender).ClientID.ToString());
}
}
|
|
|
|
 |
|
 |
I have implemented your example, and this works OK.
My question:
I need to know which row was selected with the radioButton, it can do it with Server Controls, But hOW CAn I do with this HTML input radio bUtton IN THE GridView.
Thanks in advance for your soon help,
Roxana
Roxa
|
|
|
|
 |
|
 |
You can put the index of the row in the value property of the HTML RadioButton:
<input name="MyRadioButton" type="radio"
value='<%# GetRowIndex() %>' />
GetRowIndex can be a protected method in the code behind that will return the index of the rows [0......N].
Now, when the user clicks the button after selecting the RadioButton you can retrieve the rowIndex using the Request.Form property I have described in the article. Once, you got the row index simply extract that row from the GridView row collection.
GridViewRow row = GridView1.Rows[rowIndex];
Mohammad Azam
azamsharp@gmail.com
www.gridviewguy.com
videos.gridviewguy.com
Houston, TEXAS
|
|
|
|
 |
|
 |
Hello there, To memorize checked row after postback, the only way i've found to do that is a javascript on the body onload event, it works even within a master page: - add an ID attribute on the radio button <input name="rdChoixConso" type="radio" ID="<%# Eval("n_client_cdr")%>" value='<%# Eval("n_client_cdr") %>'/> - re-check button on page load <body onload="rd=document.all('<%=Request.Form["rdChoixConso"]%>');if (rd) rd.checked=true;">
|
|
|
|
 |
|
 |
Here is another way of memorizing the selected radio button across postbacks.
http://aspadvice.com/blogs/azamsharp/archive/2007/02/20/Maintain-HTML-Radio-Button-Selection-Inside-GridView-After-Postback.aspx
Mohammad Azam
azamsharp@gmail.com
www.gridviewguy.com
videos.gridviewguy.com
Houston, TEXAS
|
|
|
|
 |
|
 |
Hi!
It is a great solution for obtaining the selected ID for example, but I need to obtain the position of the selected row in the gridview.
What is the value='<% %>' clause I should write for obtaining the position?
|
|
|
|
 |
|
 |
Why iam unable to read/find the radio button value in Gridview Control.
1 way i can read is if i set it to runat=server i could read. but it is not creating as a group i.e., it is allowing me to select all the radio button which is not supposed to work like that.
do you have any idea why iam having this problem
sree
|
|
|
|
 |
|
 |
Now i know why he's on top 25 poster on Asp.net forums...
keep Learning and you never will be out of date...
|
|
|
|
 |
|
 |
For my applicaiton, I needed to set one of the radio buttons checked based on a value from the db. Took me a little while to figure it out, but I finally got it.
class='<%# covertToChecked(Eval("DEFAULT_FLAG"))%>'
is the meat of it, I just get a boolean value from the db. If it is true I return a string that completes the css class and adds the checked attribute to the radio button. Seems like a hack, but I could not figure out how to get the eval to work without prepending "SomeAttribute=".
<script type="text/C#" runat="server">
private string covertToChecked(object check)
{
if (check.ToString() == "True")
return "checked' checked='checked'";
else
return "notChecked";
}
</script>
<asp:TemplateField HeaderText="Default">
<input name="rdoDefault" id="rdoDefault" type="radio" value='<%# Eval("DB_CONNECTION_ID") %>' class='<%# covertToChecked(Eval("DEFAULT_FLAG"))%>'/>
josh
|
|
|
|
 |