I have one radio button in gridview itemplate field. But when I am selecting the radiobutton i am unable to get the id of that row. So that based on that id textbox value will be autopopulated.
enter code here
<asp:GridView ID="gvItem" SkinID="GridView" runat="server" OnRowDataBound="gvItem_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="" Visible="false">
<ItemTemplate>
<%#Container.DataItemIndex %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButton ID="rbtnQuantity" runat="server" AutoPostBack="true" OnCheckedChanged="rbtnQuantity_CheckedChanged" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="20px" />
</asp:TemplateField>
<%--1--%>
<asp:TemplateField HeaderText="ID" SortExpression="ID">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text=' <%# Eval("ID")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="90px" />
</asp:TemplateField>
<%--2--%>
<asp:TemplateField HeaderText="Name" SortExpression="Name">
<ItemTemplate>
<asp:Label ID="lblItemName" runat="server" Text='<%# Eval("Name")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="140px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
You can try on the radiobutton click event to look for sender.parent.findcontrol("lblID").
this would be on the code-behind and for vb.net it would look like this:
Dim rowID as String = CType(CType(sender, RadioButton).Parent.FindControl("lblID"),Label).Text
Related
I have two textbox inside gridview. If 1st text contains any data then 2nd textbox should not be empty. If 1st textbox is null then no validation for 2nd textbox. Only the alert will come after filling the 1st textbox 2nd textbox shouldn't empty. How to do that?
Any idea? Please help me out.
<asp:GridView runat="server" Width="980px" ID="grdResUpdate" AutoGenerateColumns="false"
CssClass="TopMargin10 borderClass gridwrap" OnRowDataBound="grdResUpdate_RowDataBound" ShowHeader="true">
<Columns>
<asp:TemplateField HeaderText="SO #" ItemStyle-Width="70px">
<ItemTemplate>
<asp:Label runat="server" Width="70px" ID="lblSOName" CssClass="gridwrap" Text='<%# Eval("SOName")%>' />
<asp:HiddenField runat="server" ID="hdnFldSOId" Value='<%#Eval("SOId") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Test Type" ItemStyle-Width="300px" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:HiddenField runat="server" ID="testTypeIdHdnFld" Value='<%#Eval("TestTypeId") %>' />
<asp:Label runat="server" Width="150px" ID="lblTestTypeName" CssClass="gridwrap" Text='<%# Eval("TestTypeName")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Test Case Count" ItemStyle-Width="100px" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:TextBox ID="txtTestCaseCount" runat="server" HeaderText="Test Case Count" Width="80px" onkeydown="return isDigit(event)"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Environment" ItemStyle-Width="100px" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:TextBox ID="txtEnvironment" runat="server" HeaderText="Environment" Width="80px" onkeydown="return isDigit(event)"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Passed" ItemStyle-Width="100px" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:TextBox ID="txtPassed" runat="server" HeaderText="Passed" Width="80px" onkeydown="return isDigit(event)"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Failed" ItemStyle-Width="70px" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:TextBox ID="txtFailed" runat="server" HeaderText="Failed" Width="80px" onkeydown="return isDigit(event)"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="No Of Defects" ItemStyle-Width="70px" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:TextBox ID="txtDefects" runat="server" HeaderText="No Of Defects" Width="80px" onkeydown="return isDigit(event)"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Hours" ItemStyle-Width="100px" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:TextBox ID="txtHours" runat="server" HeaderText="Hours" Width="80px" onkeydown="return isDigit(event)"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Test Case Completed" ItemStyle-Width="100px" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:TextBox ID="txtTCComp" runat="server" HeaderText="Test Case Completed" Width="80px" onkeydown="return isDigit(event)"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Percentage Completed" ItemStyle-Width="100px" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:TextBox ID="txtPercComp" runat="server" HeaderText="Percentage Completed" Width="80px" onkeydown="return isDigit(event)"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle CssClass="headerTop" />
<AlternatingRowStyle CssClass="rowbgblue" />
<RowStyle CssClass="rowbginwhite" />
</asp:GridView>
I want when the user fills the txtTestCaseCount then he must have to fill txtHours
can check with onfoucsOut event
$("textbox2id").focusOut(function(){
if(!($("textbox2id").val() == ""))
{
alert("please enter a value as required");
$(this).focus();
}
})
First access gridview text boxes and then place checking code inside change event of txtTestCaseCount textbox
var textBoxOne = '#<%=grdResUpdate.ClientID%> input[id*="txtTestCaseCount"]';
var textBoxTwo = '#<%=grdResUpdate.ClientID%> input[id*="txtHours"]';
$(textBoxOne).on('change', function () {
if($(textBoxTwo).val()==""){
alert("Please fill hours textbox");
}
});
this checks if txtTestCaseCount value is filled then if textbox txtHours is not filled then alert message is shown.
Every textbox in gridview has an id generated at runtime. Use that id as a selector, like
$("#textboxid").val()
.This will give u the content of the textbox. Use it to validate the other textbox.
If suppose the id generated of txtTestCaseCount is like grdResUpdate_txtTestCaseCount then
if($("#grdResUpdate_txtTestCaseCount").val().length < 0){//Code}
I've dropdown to language based on language selection change master page.
Where as I've gridview , this will bind with data based on language .
When i change language textbox value in gridview is not changing other than that remaining control values are changing .
Here is my Code of gridview
<asp:TemplateField HeaderText="<%$ Resources:AFRResources, Status %>" ItemStyle-CssClass="gridLanguage-status"
SortExpression="STATUS" ItemStyle-HorizontalAlign="Center" HeaderStyle-ForeColor="White">
<ItemTemplate>
<asp:Label ID="lblActive" runat="server" Text='<%# Bind("ACTIVE") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle CssClass="gridLanguage-status" ForeColor="White" />
<ItemStyle CssClass="gridLanguage-status" HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="<%$ Resources:AFRResources, SeqNo %>" HeaderStyle-CssClass="gridViolation-status"
ItemStyle-CssClass="gridViolation-status" ItemStyle-HorizontalAlign="Center"
HeaderStyle-ForeColor="White" SortExpression="STATUS">
<ItemTemplate>
<asp:Label ID="lblSeqno" runat="server" Text='<%# Bind("SEQUENCENO") %>'></asp:Label>
<asp:TextBox ID="txtSeqNo" runat="server" Width="40%" Text='<%# Bind("SEQUENCENO") %>'
onchange="SetValue()" MaxLength="4" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
but you have to refresh your gridview i mean you could have a method that receives as parameter the selection from your dropdownlist you could maybe use the event SelectedIndexChanged
I have a grid with 5 columns, in which 3 are RadioButtons of different fileds. I want to have a condition of checking only one radiobutton of that row,
My code is
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="DirectPOL">
<ItemTemplate>
<asp:RadioButton ID="rdDirectPOL" runat="server" Checked='<%#Convert.ToBoolean(Eval("POL"))%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="DirectPOD">
<ItemTemplate>
<asp:RadioButton ID="rdDirectPOD" runat="server" Checked='<%# Convert.ToBoolean(Eval("POD")) %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="inDirectPOL">
<ItemTemplate>
<asp:RadioButton ID="rdIndirectPOL" runat="server" Checked='<%#Convert.ToBoolean(Eval("IsPOL"))%>' />
</ItemTemplate>
</asp:TemplateField>
In doing this i can see all the three can be checked at one time, but i want to restrict it to one at a time...,
Can any one please help me
Set the GroupName property:
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="DirectPOL">
<ItemTemplate>
<asp:RadioButton ID="rdDirectPOL" runat="server" Checked='<%#Convert.ToBoolean(Eval("POL"))%>'
GroupName="Group1" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="DirectPOD">
<ItemTemplate>
<asp:RadioButton ID="rdDirectPOD" runat="server" Checked='<%# Convert.ToBoolean(Eval("POD")) %>'
GroupName="Group1" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="inDirectPOL">
<ItemTemplate>
<asp:RadioButton ID="rdIndirectPOL" runat="server" Checked='<%#Convert.ToBoolean(Eval("IsPOL"))%>'
GroupName="Group1" />
</ItemTemplate>
</asp:TemplateField>
This way, only one RadioButton will be checked for each RadioButton with the same GroupName. In your case, you'll have to set one GroupName per row.
I want to generate serial no in gridview asp.net.
How can I do it?
try this
<asp:TemplateField>
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
</asp:TemplateField>
Note : DataItemIndex - Gets the index of the DataItem in the underlying DataSet.
<asp:GridView ID="grdCart" runat="server" Width="100%" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Sr No" HeaderStyle-Width="5%" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
<HeaderStyle CssClass="table_04" HorizontalAlign="Left"></HeaderStyle>
<ItemStyle CssClass="table_02" HorizontalAlign="Left"></ItemStyle>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:TemplateField HeaderText="S.No" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblSNo" runat="server" Text='<%#Container.DataItemIndex+1 %>' CssClass="form-label"></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" Width="10px"></ItemStyle>
</asp:TemplateField>
I have a GridView that I use to show my users the result of a search. I want to allow them to choose which columns are shown on the GridView when performing their search. Simple enough, yes? I wanted to try doing this using just databinding, no events. Unfortunately, my code fails to update the GridView using checkboxes bound to the column's Visible property. The state of the chechboxes changes, but the Visible property of the columns does not.
Snippet of Search.aspx:
<myControl:FacultyGridView ID="FacultyGridView1" runat="server" />
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Text='<%# Eval("HeaderText") %>' Checked='<%# Bind("Visible") %>' AutoPostBack=true/></ItemTemplate>
</asp:Repeater>
Code-behind snippet in Search.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
Repeater1.DataSource = FacultyGridView1.GridView.Columns;
Repeater1.DataBind();
}
To be clear, the GridView is exposed as a public property of a user control named FacultyGridView. Relevant snippet of FacultyGridView.ascx:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
AllowPaging="True" AllowSorting="True" PageSize="25">
<PagerSettings Mode="NumericFirstLast" Position="TopAndBottom" />
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True" SortExpression="Name" />
<asp:TemplateField HeaderText="University" SortExpression="UniversityID">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("University.Name") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Division">
<ItemTemplate>
<asp:Repeater ID="Repeater1" runat="server" DataSource='<%# Eval("DivisionMemberships") %>'>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Division.Name") %>'></asp:Label>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Title" HeaderText="Title" ReadOnly="True" SortExpression="Title" />
<asp:TemplateField HeaderText="Research Type">
<ItemTemplate>
<asp:Repeater ID="Repeater1" runat="server" DataSource='<%# Eval("ResearchTypeMappings") %>'>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ResearchType.Name") %>'></asp:Label>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Expertise" HeaderText="Expertise" ReadOnly="True" SortExpression="Expertise" />
<asp:HyperLinkField DataNavigateUrlFields="Website" DataTextField="Website" HeaderText="Website"
SortExpression="Website" />
<asp:BoundField DataField="Phone" HeaderText="Phone" ReadOnly="True" SortExpression="Phone" />
<asp:TemplateField HeaderText="Email Address" SortExpression="EmailAddress">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("EmailAddress", "mailto:{0}") %>'
Text='<%# Eval("EmailAddress") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Finally, I should mention that the GridView is bound by a Button on the page, but I am not getting updates to the Visible property whether I play with the checkboxes before or after databinding. Furthermore, I have not seen my desired behavior when binding the repeater only on the first Page_Load() using if(!IsPostBack), nor by not using Checkbox.AutoPostback true or false. Any clue as to what I'm doing wrong? I expect it to be something simple, but I'm a bit green here.
As a note: I know how to do this easily with events, but I want to do it with databinding as a learning exercise.
Probably because every time the grid is bound to the data, the column & settings are recreated (with-out your changes).