In a gridview how can I do single radiobutton select without using JavaScript
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="GroupName" />
</ItemTemplate>
</asp:TemplateField
Give Different name to each radio button control and remove groupname attribute
e.g.
<asp:RadioButton ID="RadioButton2" runat="server" />
Related
I have one column of TextBox and one column of CheckBox in ItemTemplate in a GridView and number of rows are generating dynamically.
When I click on CheckBox the value of TextBox is changing but when I am inserting the values into database, default value which I have given in TextBox it is saving that.
<asp:GridView ID="grdData" runat="server" Style="text-align: center;">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" onclick="changeTextValue(this)" />
</ItemTemplate>
<HeaderTemplate>
<!-- <asp:CheckBox ID="CheckBox2" runat="server"OnClick="CheckAllEmp(this)" />-->
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label ID="Status_Header" runat="server" Text="Status" />
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Enabled="false" Text="1" ClientIDMode="Static"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I found solution, remove Enabled="false" property from TextBox1 and check.
<asp:TextBox ID="TextBox1" runat="server" Enabled="false" Text=1 ClientIDMode="Static"></asp:TextBox>
If you want to disabled textbox from end user, I suggest you to use LABEL control instead of TEXTBOX.
Here is the jQuery function for LABEL control.
<script>
function changeTextValue(chk) {
var currentTextID = $(chk).parents('tr').find('span[id$="Label1"]');
alert(chk.checked + ": " + currentTextID.text());
if (chk.checked == true)
currentTextID.text("Present");
else
currentTextID.text("Absent");
}
</script>
Label control should be like below:
<asp:Label ID="Label1" runat="server" Text="Absent" EnableViewState="false" ClientIDMode="Static"></asp:Label>
Please let me know if you have any questions.
In my gridView I've inserted the edit command name for every single row.
Now I need when the database value of myDate is not null stopping the edit in this row.
I tried this solution, but in GV see the icon stop.gif when the database value of myDate is not null, but if click in stop.gif the edit row is open, why?
Can you help me?
Thanks in advance.
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<center>
<asp:ImageButton ID="imgbtnEdit" CommandName="Edit" runat="server"
ImageUrl='<%#(String.IsNullOrEmpty(Eval("myDate").ToString()) ? "/Images/edit.gif" : "/Images/stop.gif")%>'
ToolTip="Edit" /></center>
</ItemTemplate>
<EditItemTemplate>
<center>
<asp:ImageButton ID="imgbtnUpdate" CommandName="Update" runat="server" ImageUrl="/Images/update.gif"
ToolTip="Update" />
<asp:ImageButton ID="imgbtnCancel" runat="server" CommandName="Cancel" ImageUrl="/Images/cancel.gif"
ToolTip="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
If you just make the image url blank, it does not mean that you are not rendering the control. The button will still render. What you could do instead is like below
<asp:ImageButton ID="imgbtnEdit" CommandName="Edit" runat="server"
ImageUrl='/Images/stop.gif'
Visbile = '<%#Eval("myDate").HasValue %>'
ToolTip="Edit" />
<asp:datalist ID="Datalist1" runat="server"
Width="500px" >
<ItemTemplate>
<asp:Button ID="btnviewfullprofile" runat="server" Text="View Full Profile" ToolTip="Click for Full Profile of User" CommandArgument='<%#Eval("Uid")%>' CommandName="fullprofile" />
<asp:Button ID="sendinterest" runat="server" Text="Send Interest" CommandArgument='<%#Eval("Uid")%>' CommandName="sendinterest" />
<asp:Label ID="lblstatus" runat="server" Visible="False" ></asp:Label>
</ItemTemplate>
</asp:datalist>
text of label will change according to the value of status stored in database.
code for button
if (e.CommandName == "fullprofile")
{
int Id = int.Parse(e.CommandArgument.ToString());
Response.Redirect("~/FullProfile.aspx?Id=" + Id);
`enter code here` }
but what should i write for label so that text of label should change itself based on value of status stored in database
If I understand you correctly, you need to change the HTML to something like:
<asp:Label ID="lblstatus" runat="server" Visible="False"
Text='<%# Eval("DatabaseField") %>' />
You are already using this for the CommandArgument of the button. Obviously you need to replace 'DatabaseField' with the name of the field that you want to show as text. ASP.net will fill the Text attribute with the correct value from your datasource.
as you are binding commandargument of the button from database, same way you can bind the text property of the label
<asp:Label ID="lblstatus" runat="server" Visible="False" Text= '<%#Eval("textfield")%>' ></asp:Label>
If you need more advance control then you need to set them when items are getting bound see here fore details http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datalist.itemdatabound.aspx
I am trying to add edit, delete button on my gridview using,
<asp:CommandField HeaderText="Edit/Delete" ShowEditButton="true" ShowDeleteButton="True" />
however it looks like this now,
I want Delete button on a new row, what can I do ?
like this
Edit
Delete
Try
first convert commandbuttons to template then
adding <br /> between edit button and delete button
UPDATE In Gridview Task then Select the commands that you want to convert to TemplateField in "Selected Fields:" then check your source code. You will see in the ItemTemplate
<asp:ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit"></asp:LinkButton>
<br />
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
<asp:GridView ID="UserTable" runat="server" AllowPaging="False" SelectedIndex="0" DataKeyNames="UserID" ShowHeaderWhenEmpty="True"
OnRowDeleting="UserTable_RowDeleting" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Edit Controls" ItemStyle-Width="15%">
<ItemTemplate>
<%-- <asp:LinkButton ID="lnk_Edit" ToolTip="Edit User" CommandArgument='<%# Eval("UserID") %>' CommandName="Edit1" runat="server">--%>
<asp:ImageButton ID="img_Edit" src="Styles/Images/Edit.jpg" runat="server" style="border-style: none" CommandArgument='<%# Eval("UserID") %>'
CommandName="Edit1" />
<%--</asp:LinkButton>--%>
<asp:PopupControlExtender ID="PopUCtrlExt_Edit" runat="server" DynamicServicePath=""
Enabled="True" ExtenderControlID="" TargetControlID="img_Edit" PopupControlID="pnl_updateUser">
</asp:PopupControlExtender>
I wanted to get a pop up when I click the edit image inside my grid view. When I tried with a edit image inside a link the pop up was doing post back so I had to remove the link. Now How can i get the values of the selected row and use that value in the pop up panel which has
<asp:ListBox ID="listboxE_RoleName" runat="server" DataSourceID="SurelyKnown" DataTextField="RoleName" DataValueField="RoleName"></asp:ListBox>
<asp:TextBox ID="txtE_Email" runat="server" CssClass="style23"></asp:TextBox>
I want to edit the selected value. How to populate the values of selected row in the pop up panel in client side. If possible also a fix for the pop up postback when I use the image button inside the link. Thanks
Check these links
http://mattberseth.com/blog/2007/07/modalpopupextender_example_for.html
http://mattberseth.com/blog/2008/06/masterdetail_with_the_gridview_1.html
http://mattberseth.com/blog/2008/04/masterdetail_with_the_gridview.html
http://www.aspdotnet-suresh.com/2011/03/how-to-show-modalpopup-to-edit-gridview.html