Unable to read RadioButton inside nested GridView - c#

I have a nested GridView to 5 levels and I am having hard time accessing which RadioButtonList is selected in 2nd level of GridView. (first level is named gvSecondLevel so please don't get confused). I have to now access from gvThirdLevel (which is actually 2nd level grid as you will see in code). I am not sure whether the issue is with ASPX code or c# code. I have tried putting rbThirdLevel inside TemplateField and without it. But I can't access it either way. Here is the aspx code:
<table align="left">
<tr>
<td colspan="2">
<asp:GridView ID="gvSecondLevel" runat="server" AutoGenerateColumns="False" Width="800px"
ShowFooter="True" BorderStyle="none" DataKeyNames="CallCategory_ID" OnRowDataBound="gvSecondLevel_OnRowDataBound"
OnRowCommand="gvSecondLevel_RowCommand" OnRowDeleting="gv_RowDeleting" AllowPaging="true"
PageSize="10" OnPageIndexChanging="gvSecondLevel_PageIndexChanging" OnRowCreated="gvSecondLevel_RowCreated" >
<Columns>
<asp:TemplateField HeaderText="ID" HeaderStyle-Width="20px">
<ItemTemplate>
<asp:Label ID="lblBusinessID" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"CallCategory_ID") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Width="20px" />
</asp:TemplateField>
<asp:BoundField DataField="CallCategory_Name" HeaderText="Call Category Name 2nd" />
<asp:TemplateField HeaderText="" ItemStyle-Width="20px">
<ItemTemplate>
<asp:LinkButton ID="lbtnDeleteSecondLevel" CommandArgument='<%# Eval("CallCategory_ID") %>'
CommandName="Delete" runat="server"></asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="20px" />
</asp:TemplateField>
<asp:TemplateField HeaderStyle-BorderStyle="None" FooterStyle-BorderStyle="None"
ItemStyle-BorderStyle="None">
<ItemTemplate>
<tr>
<td id="td_div<%# Eval("CallCategory_ID") %>" colspan="100%" style="border: none;">
<div id="div<%# Eval("CallCategory_ID") %>" style="overflow: auto; display: none;
position: relative; left: 15px; overflow: auto">
<asp:GridView ID="gvThirdLevel" runat="server" Width="95%" AutoGenerateColumns="false"
ShowFooter="true" BorderStyle="none" DataKeyNames="CallCategory_ID" OnRowDataBound="gvThirdLevel_OnRowDataBound"
OnRowCommand="gvThirdLevel_RowCommand" OnRowDeleting="gv_RowDeleting">
<Columns>
<asp:TemplateField HeaderText="ID" Visible="true" HeaderStyle-Width="20px">
<ItemTemplate>
<asp:Label ID="lblCallCategoryID" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "CallCategory_ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CallCategory_Name" HeaderText="Call Category Name 3rd" />
<asp:TemplateField HeaderText="" ItemStyle-Width="20px">
<ItemTemplate>
<asp:LinkButton ID="lbtnDeleteThirdLevel" CommandArgument='<%# Eval("CallCategory_ID") %>'
CommandName="Delete" runat="server">Deactivate</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-BorderStyle="None" FooterStyle-BorderStyle="None"
ItemStyle-BorderStyle="None">
<ItemTemplate>
<tr>
<td id="td_div1<%# Eval("CallCategory_ID") %>" colspan="100%" style="border: none;">
<div id="div1<%# Eval("CallCategory_ID") %>" style="overflow: auto; display: none;
position: relative; left: 15px; overflow: auto">
<asp:GridView ID="gvFourthLevel" runat="server" Width="95%" AutoGenerateColumns="false"
BorderStyle="none" ShowFooter="true" OnRowDataBound="gvFourthLevel_OnRowDataBound"
OnRowCommand="gvFourthLevel_RowCommand" OnRowDeleting="gv_RowDeleting" DataKeyNames="CallCategory_ID">
<Columns>
<asp:TemplateField HeaderText="ID" HeaderStyle-Width="20px">
<ItemTemplate>
<asp:Label ID="lblCallCategoryID_Fourth" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "CallCategory_ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CallCategory_Name" HeaderText="Call Category Name 4th" />
<asp:TemplateField HeaderText="" ItemStyle-Width="20px">
<ItemTemplate>
<asp:LinkButton ID="lbtnDeleteFourthLevel" CommandArgument='<%# Eval("CallCategory_ID") %>'
CommandName="Delete" runat="server">Deactivate</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-BorderStyle="None" FooterStyle-BorderStyle="None"
ItemStyle-BorderStyle="None">
<ItemTemplate>
<tr>
<td id="td_div2<%# Eval("CallCategory_ID") %>" colspan="100%" style="border: none;">
<div id="div2<%# Eval("CallCategory_ID") %>" style="overflow: auto; display: none;
position: relative; left: 15px; overflow: auto">
<asp:GridView ID="gvFifthLevel" runat="server" Width="95%" AutoGenerateColumns="false"
BorderStyle="none" ShowFooter="true" OnRowDataBound="gvFifthLevel_OnRowDataBound"
OnRowCommand="gvFifthLevel_RowCommand" OnRowDeleting="gv_RowDeleting" DataKeyNames="CallCategory_ID">
<Columns>
<asp:TemplateField HeaderText="ID" HeaderStyle-Width="20px">
<ItemTemplate>
<asp:Label ID="lblCallCategoryID_Fifth" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "CallCategory_ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CallCategory_Name" HeaderText="Call Category Name 5th" />
<asp:TemplateField HeaderText="" ItemStyle-Width="20px">
<ItemTemplate>
<asp:LinkButton ID="lbtnDeleteFifthLevel" CommandArgument='<%# Eval("CallCategory_ID") %>'
CommandName="Delete" runat="server">Deactivate</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-BorderStyle="None" FooterStyle-BorderStyle="None"
ItemStyle-BorderStyle="None">
<ItemTemplate>
<tr>
<td id="td_div3<%# Eval("CallCategory_ID") %>" colspan="100%" style="border: none;">
<div id="div3<%# Eval("CallCategory_ID") %>" style="overflow: auto; display: none;
position: relative; left: 15px; overflow: auto">
<asp:GridView ID="gvSixthLevel" runat="server" Width="95%" AutoGenerateColumns="false"
BorderStyle="none" ShowFooter="true" OnRowDataBound="gvSixthLevel_OnRowDataBound"
OnRowCommand="gvSixthLevel_RowCommand" OnRowDeleting="gv_RowDeleting">
<Columns>
<asp:BoundField DataField="CallCategory_ID" HeaderText="ID" HeaderStyle-Width="20px" />
<asp:BoundField DataField="CallCategory_Name" HeaderText="Call Category Name 6th" />
<asp:TemplateField HeaderText="" ItemStyle-Width="20px">
<ItemTemplate>
<asp:LinkButton ID="lbtnDeleteSixthLevel" CommandArgument='<%# Eval("CallCategory_ID") %>'
CommandName="Delete" runat="server">Deactivate</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:RadioButtonList ID="rbSixthLevel" runat="server"
onselectedindexchanged="rbSixthLevel_SelectedIndexChanged" RepeatDirection="Horizontal" AutoPostBack="True">
<asp:ListItem Selected="True">Active</asp:ListItem>
<asp:ListItem>Inactive</asp:ListItem>
</asp:RadioButtonList>
</div>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:RadioButtonList ID="rbFifthLevel" runat="server" onselectedindexchanged="rbFifthLevel_SelectedIndexChanged" RepeatDirection="Horizontal" AutoPostBack="True">
<asp:ListItem Selected="True">Active</asp:ListItem>
<asp:ListItem>Inactive</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:RadioButtonList ID="rbFourthLevel" runat="server" onselectedindexchanged="rbFourthLevel_SelectedIndexChanged" RepeatDirection="Horizontal" AutoPostBack="True">
<asp:ListItem Selected="True">Active</asp:ListItem>
<asp:ListItem>Inactive</asp:ListItem>
</asp:RadioButtonList>
</div>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButtonList ID="rbThirdLevel" runat="server" onselectedindexchanged="rbThirdLevel_SelectedIndexChanged" RepeatDirection="Horizontal" AutoPostBack="True">
<asp:ListItem Selected="True">Active</asp:ListItem>
<asp:ListItem>Inactive</asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateField>
</div>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:RadioButtonList ID="rbSecondLevel" runat="server" onselectedindexchanged="rbSecondLevel_SelectedIndexChanged"
RepeatDirection="Horizontal" AutoPostBack="True">
<asp:ListItem Selected="True">Active</asp:ListItem>
<asp:ListItem>Inactive</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
</table>
C# code is just return "Active" even when I select "Inactive". Please guide what is the correct way to access rbThirdLevel
protected void rbThirdLevel_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (GridViewRow row in gvSecondLevel.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
GridView gvThirdLevel = (GridView)row.FindControl("gvThirdLevel");
if (gvThirdLevel != null)
{
RadioButtonList rbThirdLevel = gvSecondLevel.Rows[row.RowIndex].FindControl("rbThirdLevel") as RadioButtonList;
string radiovalue = (gvSecondLevel.Rows[row.RowIndex].FindControl("rbThirdLevel") as RadioButtonList).SelectedItem.Value;
if (rbThirdLevel.SelectedValue == "Inactive")
{
//code to display Deactivated rows
}
if (rbThirdLevel.SelectedValue == "Active")
{
//code to display Activated rows
}
}
}
}
}

Related

Edit on child gridview collapse the expansion

I have a parent grid GVInvoiceDet. CRUD operation on this grid is working fine. In each row of the parent, I have child grid GVTaxDetails which opens on click of image ie expand/collapse feature.
I am looking for CRUD within child grid also. But when I click on edit within child, the texbox for editing doesn't appear and the parent grid collapses.
Here is child grid rowediting code
protected void GVTaxDetails_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView gvTemp = (GridView)sender;
gvUniqueID = gvTemp.UniqueID;
//gvEditIndex = e.NewEditIndex;
gvTemp.EditIndex = e.NewEditIndex;
GVInvoiceDet.DataBind();
}
Parent row editing code
protected void GVInvoiceDet_RowEditing(object sender, GridViewEditEventArgs e)
{
GVInvoiceDet.EditIndex = e.NewEditIndex;
GVInvoiceDet.DataBind();
BindItemGrid();
}
ASPX file :
<asp:GridView ID="GVInvoiceDet" runat="server" Width="100%" AutoGenerateColumns="False"
HorizontalAlign="Left" BorderStyle="Outset" OnRowCancelingEdit="GVInvoiceDet_RowCancelingEdit"
OnRowEditing="GVInvoiceDet_RowEditing" OnRowDataBound="GVInvoiceDet_RowDataBound" ShowFooter="True"
OnRowCommand="GVInvoiceDet_RowCommand" OnRowUpdating="GVInvoiceDet_RowUpdating"
OnRowDeleting="GVInvoiceDet_RowDeleting" OnRowDeleted="GVInvoiceDet_RowDeleted"
OnRowUpdated="GVInvoiceDet_RowUpdated" AllowSorting="True" DataSourceID="DSItemGrid" DataKeyNames="invoiceno,itemcd">
<HeaderStyle BackColor="#0000ff" ForeColor="Yellow" />
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<EditRowStyle BackColor="#FFFFCC" ForeColor="#330099" />
<AlternatingRowStyle BackColor="#FE9CD5" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href="javascript:expandcollapse('div<%# Eval("itemcd") %>', 'one');">
<img id="imgdiv<%# Eval("itemcd") %>" alt="Click to show/hide Tax Details <%# Eval("itemcd") %>" border="0" src="Images/plus.png" />
</a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="10%" HeaderText="Item Code" SortExpression="itemcd">
<ItemTemplate>
<asp:Label ID="lblItemCode" runat="server" Text='<%# Eval("itemcd")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtItemCode" Width="90%" runat="server" Text='<%# Eval("itemcd")%>' Enabled="false"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtItemCode" Width="90%" runat="server" Text='' Enabled="false"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="10%" HeaderText="HSN Code" SortExpression="hsncd">
<ItemTemplate>
<asp:Label ID="lblItemHSNCode" runat="server" Text='<%# Eval("hsncd")%>'></asp:Label><asp:HiddenField ID="hdnItemGST" runat="server" Value='<%# Eval("itempercentage") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtItemHSN" Width="90%" runat="server" Text='<%# Eval("hsncd")%>' Enabled="false"></asp:TextBox><asp:HiddenField ID="hdnEditItemGST" runat="server" Value='<%# Eval("itempercentage") %>' />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtItemHSN" Width="90%" runat="server" Text='' Enabled="false"></asp:TextBox><asp:HiddenField ID="hdnFooterItemGST" runat="server" Value='<%# Eval("itempercentage") %>' />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="25%" HeaderText="Item Description" SortExpression="itemdesc">
<ItemTemplate>
<asp:Label ID="lblItemDesc" runat="server" Text='<%# Eval("itemdesc")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblItemDesc" runat="server" Text='<%# Eval("itemdesc")%>' Visible="false"></asp:Label><asp:HiddenField ID="hdnItemDesc" runat="server" Value='<%# String.Format("{0}-{1}-{2}",Eval("itemcd"),Eval("hsncd"),Eval("itempercentage")) %>' />
<asp:DropDownList ID="eddlItemDesc" runat="server" AutoPostBack="true" OnSelectedIndexChanged="eddlItemDesc_SelectedIndexChanged"></asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="fddlItemDesc" runat="server" AutoPostBack="true" OnSelectedIndexChanged="fddlItemDesc_SelectedIndexChanged"></asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="5%" HeaderText="Quantity">
<ItemTemplate>
<asp:Label ID="lblItemQty" runat="server" Text='<%# Eval("quantity")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtItemQty" Width="90%" runat="server" Text='<%# Eval("quantity")%>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtItemQty" Width="90%" MaxLength="100" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="5%" HeaderText="Unit Rate">
<ItemTemplate>
<asp:Label ID="lblItemUnitRate" runat="server" Text='<%# Eval("unitrate")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtItemUnitRate" Width="90%" runat="server" Text='<%# Eval("unitrate")%>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtItemUnitRate" Width="90%" MaxLength="100" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="5%" HeaderText="Unit Value">
<ItemTemplate>
<asp:Label ID="lblItemUnitValue" runat="server" Text='<%# Eval("unitvalue")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtItemUnitValue" Width="90%" runat="server" Text='<%# Eval("unitvalue")%>' Enabled="false"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtItemUnitValue" Width="90%" MaxLength="100" runat="server" Enabled="false"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="5%" HeaderText="Final Value">
<ItemTemplate>
<asp:Label ID="lblItemFinalValue" runat="server" Text=''></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtItemFinalValue" Width="90%" runat="server" Text='' Enabled="false"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtItemFinalValue" Width="90%" MaxLength="100" runat="server" Enabled="false"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" HeaderText="Edit" />
<asp:TemplateField HeaderText="Delete" ItemStyle-Width="5%">
<ItemTemplate>
<asp:LinkButton ID="linkDeleteInvoiceItem" CommandName="DeleteItem" runat="server">Delete</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="linkAddInvoiceItem" CommandName="AddItem" runat="server">Add</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<tr>
<td colspan="100%">
<div id="div<%# Eval("itemcd") %>" style="display: none; position: relative; left: 15px; overflow: auto; width: 97%">
<asp:GridView ID="GVTaxDetails" BackColor="White" Width="100%" Font-Size="Small" AutoGenerateColumns="false"
runat="server" DataKeyNames="invoiceno,itemcd,valuecd" ShowFooter="True" OnRowUpdating="GVTaxDetails_RowUpdating"
OnRowCommand="GVTaxDetails_RowCommand" OnRowEditing="GVTaxDetails_RowEditing" GridLines="None"
OnRowUpdated="GVTaxDetails_RowUpdated" OnRowCancelingEdit="GVTaxDetails_CancelingEdit"
OnRowDataBound="GVTaxDetails_RowDataBound" OnRowDeleting="GVTaxDetails_RowDeleting" OnRowDeleted="GVTaxDetails_RowDeleted"
ShowHeaderWhenEmpty="true" BorderStyle="Double" BorderColor="#0083C1">
<RowStyle BackColor="Gainsboro" />
<AlternatingRowStyle BackColor="White" />
<HeaderStyle BackColor="#0083C1" ForeColor="White" />
<FooterStyle BackColor="White" />
<Columns>
<asp:TemplateField ItemStyle-Width="5%" HeaderText="SL No">
<ItemTemplate>
<asp:Label ID="lblViewTaxSlno" runat="server" Text='<%# Eval("slno")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtViewTaxSlno" runat="server" Text='<%# Eval("slno")%>' Enabled="false"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtViewTaxSlno" MaxLength="3" Width="80%" runat="server" Text='<%# Convert.ToInt32(Container.DataItemIndex) + 1 %>' Enabled="false"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="15%" HeaderText="Value">
<ItemTemplate>
<asp:HiddenField ID="hdnViewTaxDesc" runat="server" Value='<%# Eval("valuecd") %>' />
<asp:Label ID="lblViewTaxDesc" runat="server" Text='<%# Eval("valuedesc")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:HiddenField ID="hdnViewTaxDesc" runat="server" Value='<%# Eval("valuecd") %>' />
<asp:DropDownList ID="eddlViewTaxDesc" Width="90%" runat="server" AutoPostBack="true" OnSelectedIndexChanged="eddViewTaxDesc_SelectedIndexChanged"></asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:HiddenField ID="hdnViewTaxDesc" runat="server" Value='<%# Eval("valuecd") %>' />
<asp:DropDownList ID="fddViewTaxDesc" Width="90%" runat="server" OnSelectedIndexChanged="fddlViewTaxDesc_SelectedIndexChanged"></asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="3%" HeaderText="Amount">
<ItemTemplate>
<asp:Label ID="lblViewTaxAmount" runat="server" Text='<%# Eval("value")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtViewTaxAmount" runat="server" Text='<%# Eval("value")%>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtViewTaxAmount" runat="server" Text='<%# Eval("value")%>'></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="7%" HeaderText="Ref. Sl No">
<ItemTemplate>
<asp:Label ID="lblViewTaxRefNo" runat="server" Text='<%# Eval("refslno")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:HiddenField ID="hdnViewTaxRefNo" runat="server" Value='<%# Eval("refslno") %>' />
<asp:DropDownList ID="eddlViewTaxRefNo" Width="90%" runat="server" AutoPostBack="false"></asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="fddViewTaxRefNo" Width="90%" runat="server" AutoPostBack="false"></asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="10%" HeaderText="Tax-Mode">
<ItemTemplate>
<asp:Label ID="lblViewTaxMode" runat="server" Text='<%# Eval("absper").ToString()=="A"?"Absolute":"Percentage"%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:HiddenField ID="hdnViewTaxMode" runat="server" Value='<%# Eval("absper") %>' />
<asp:DropDownList ID="eddlViewTaxMode" Width="90%" runat="server" AutoPostBack="false">
<asp:ListItem Value="-1" Text="-Select Mode-" Selected="True"></asp:ListItem>
<asp:ListItem Value="A" Text="Absolute"></asp:ListItem>
<asp:ListItem Value="P" Text="Percentage"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="fddlViewTaxMode" Width="95%" runat="server" AutoPostBack="false">
<asp:ListItem Value="-1" Text="-Select Mode-" Selected="True"></asp:ListItem>
<asp:ListItem Value="A" Text="Absolute"></asp:ListItem>
<asp:ListItem Value="P" Text="Percentage"></asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="10%" HeaderText="Operation">
<ItemTemplate>
<asp:Label ID="lblViewTaxOperation" runat="server" Text='<%# Eval("addsub").ToString()=="A"?"Add":"Subtract"%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:HiddenField ID="hdnViewTaxOperation" runat="server" Value='<%# Eval("addsub") %>' />
<asp:DropDownList ID="eddlViewTaxOperation" Width="90%" runat="server" AutoPostBack="false">
<asp:ListItem Value="-1" Text="-Select Operation-" Selected="True"></asp:ListItem>
<asp:ListItem Value="A" Text="Add"></asp:ListItem>
<asp:ListItem Value="S" Text="Subtract"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="fddlViewTaxOperation" Width="90%" runat="server" AutoPostBack="false">
<asp:ListItem Value="-1" Text="-Select Operation-" Selected="True"></asp:ListItem>
<asp:ListItem Value="A" Text="Add"></asp:ListItem>
<asp:ListItem Value="S" Text="Subtract"></asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="3%" HeaderText="Final Amount">
<ItemTemplate>
<asp:Label ID="lblViewTaxFinalAmount" runat="server" Text='<%# Eval("finalvalue")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtViewTaxFinalAmount" runat="server" Text='<%# Eval("finalvalue")%>' Enabled="false"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtViewTaxFinalAmount" runat="server" Text='<%# Eval("finalvalue")%>' Enabled="false"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Edit" ShowEditButton="True" />
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="linkDeleteTaxDetails" CommandName="Delete" runat="server">Delete</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="linkAddTaxDetails" CommandName="AddTax" runat="server">Add</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="DSItemGrid" runat="server" ConnectionString="<%$ ConnectionStrings:GSTCS %>" ProviderName="<%$ ConnectionStrings:GSTCS.ProviderName %>"
SelectCommand="select invoiceno, dt.itemcd itemcd, mast.itemdesc itemdesc, mast.hsncd hsncd, dt.quantity quantity,
mast.unitrate unitrate, dt.unitvalue unitvalue, mast.itempercentage itempercentage
from GSTINVOICEDT dt join GSTITEMMASTER mast on (dt.itemcd = mast.itemcd and dt.unitcode = mast.unitcode and dt.projectcode = mast.projectcode)
where dt.unitcode = :unitCode and dt.projectCode = :projCode and dt.invoiceno = :invoiceNo order by invoiceno, itemcd">
<SelectParameters>
<asp:SessionParameter DefaultValue="05" Name="unitCode" SessionField="unit" />
<asp:SessionParameter DefaultValue="0501" Name="projCode" SessionField="project" />
<asp:SessionParameter DefaultValue="INVOICENO" Name="invoiceNo" SessionField="invoiceNo" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
I got the work done... Posting the code for others if come across similar situation.
In parent rowdatabound have added code to keep the div open and update the editIndex.
protected void GVInvoiceDet_RowDataBound(object sender, GridViewRowEventArgs e) {
GridViewRow row = e.Row;
if(row.RowType == DataControlRowType.Header)
{
return;
}
else if (row.RowType == DataControlRowType.DataRow )
{
//Find Child GridView control
GridView gvTax = new GridView();
gvTax = (GridView)row.FindControl("GVTaxDetails");
if (gvTax.UniqueID == gvUniqueID)
{
gvTax.EditIndex = gvEditIndex;
//Expand the Child grid
ClientScript.RegisterStartupScript(GetType(), "Expand", "<SCRIPT LANGUAGE='javascript'>expandcollapse('div" + ((DataRowView)e.Row.DataItem)["itemcd"].ToString() + "','one');</script>");
}
}
}
expandcollapse is function on aspx side:
function expandcollapse(obj, row) {
var div = document.getElementById(obj);
var img = document.getElementById('img' + obj);
if (div.style.display == "none") {
div.style.display = "block";
if (row == 'alt') {
img.src = "Images/minus.png";
}
else {
img.src = "Images/minus.png";
}
img.alt = "Close View Taxes";
}
else {
div.style.display = "none";
if (row == 'alt') {
img.src = "Images/plus.png";
}
else {
img.src = "Images/plus.png";
}
img.alt = "Expand View Taxes";
}
}

gridview edit mode is not getting fired on single click

I want to edit the record in gridview on single click. My gridview is placed inside update panel.
There is a search textbox given and when I type anything in search textbox "txt_Search_TextChanged" event is fired and that text is searched in database and that particular record is fetched and bind to the grid.
Now my problem is: If I click on edit button of grid without searching, then event is fired. But if I search any record and then I click on edit button, it takes 2 click to give result. I have written a script for textbox which is as follows:
enter code here
<script>
function RefreshUpdatePanel() {
__doPostBack('<%= txt_Search.ClientID %>', '');
};
below is aspx code
<table width="100%">
<tr>
<td align="center">
<div style="border-width: 2px; border-style: solid; border-color: #FDAC4C; width: 95%; border-radius: 10px;">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:GridView ID="grd_Master" ShowFooter="false" runat="server" Width="98%" AllowPaging="true" PagerStyle-CssClass="paging"
OnPageIndexChanging="grd_Master_PageIndexChanging"
PageSize="8" AutoGenerateColumns="False" BorderWidth="0" BorderStyle="Solid" BorderColor="#FDAC4C" OnRowEditing="grd_Master_RowEditing" ShowHeaderWhenEmpty="true">
<AlternatingRowStyle BackColor="#FFFFFF" Height="30px" BorderStyle="Dotted" BorderWidth="1"
BorderColor="#DDDDDD" />
<RowStyle BackColor="#FFF0DD" Height="30px" BorderStyle="Dotted" BorderWidth="1"
BorderColor="#DDDDDD" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Serial No.<br />
</HeaderTemplate>
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
<ItemStyle HorizontalAlign="Right" Width="10%" CssClass="grdrow"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lblSRNO" runat="server" Style="padding-right: 50px" Text='<%#Container.DataItemIndex+1 %>'></asp:Label>
<asp:Label ID="Cooling_Code" runat="server" Visible="false" Text='<% #Bind("Cool_Code")%>'></asp:Label>
<asp:Label ID="lblProdGrpCode" runat="server" Style="padding-left: 100px" Text='<% #Bind("Prod_Grp_Code")%>' Visible="false"></asp:Label>
<asp:Label ID="lblSubProdGrpCode" runat="server" Style="padding-left: 100px" Text='<% #Bind("Sub_Prod_Code")%>' Visible="false"></asp:Label>
<asp:Label ID="lblMakeCode" runat="server" Style="padding-left: 100px" Text='<% #Bind("Make_Code")%>' Visible="false"></asp:Label>
<asp:Label ID="lblRegerCode" runat="server" Style="padding-left: 100px" Text='<% #Bind("Refg_Code")%>' Visible="false"></asp:Label>
<asp:Label ID="lblCompressorCode" runat="server" Style="padding-left: 100px" Text='<% #Bind("Comp_Code")%>' Visible="false"></asp:Label>
<asp:Label ID="lblFilePath" runat="server" Visible="false" Style="padding-left: 100px" Text='<% #Bind("Document_Path")%>'></asp:Label>
</ItemTemplate>
<HeaderStyle CssClass="grdheader" Width="10%" />
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Cooling Name
</HeaderTemplate>
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
<ItemStyle HorizontalAlign="Left" Width="20%" CssClass="grdrow"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lblCoolingName" runat="server" Style="padding-left: 10px" Text='<% #Bind("Cool_Name")%>'></asp:Label>
</ItemTemplate>
<HeaderStyle CssClass="grdheader" Width="20%" />
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Short Name
</HeaderTemplate>
<HeaderStyle HorizontalAlign="Left" CssClass="grdheader" Width="15%"></HeaderStyle>
<ItemStyle HorizontalAlign="Left" Width="15%" CssClass="grdrow"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lblCoolingShortName" runat="server" Style="padding-left: 10px" Text='<% #Bind("Cool_Short_Name")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Cooling Description
</HeaderTemplate>
<ItemStyle HorizontalAlign="left" Width="45%" CssClass="grdrow"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lblCoolingDescr" runat="server" Style="padding-left: 10px" Text='<% #Bind("Cool_Descr")%>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" CssClass="grdheader" Width="45%"></HeaderStyle>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Action<br />
</HeaderTemplate>
<HeaderStyle HorizontalAlign="Left" CssClass="grdheader" Width="10%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" Width="10%" CssClass="grdrow"></ItemStyle>
<ItemTemplate>
<asp:ImageButton ID="imgbtnEdit" runat="server" ImageUrl="~/images/Edit.png" Width="20px" ToolTip="Edit" CommandName="Edit" Height="20px" />
<asp:ImageButton ID="ImageDelete" runat="server" ImageUrl="~/images/trash1.png" ToolTip="Delete" OnClick="ImageDelete_Click" Width="25px" Height="20px" OnClientClick="return confirmDelete()" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle HorizontalAlign="Left" BorderWidth="0" BorderStyle="None" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txt_Search" />
<asp:PostBackTrigger ControlID="grd_Master" />
</Triggers>
</asp:UpdatePanel>
</div>
</td>
</tr>
</table>
Below is cs code for rowediting
protected void grd_Master_RowEditing(object sender, GridViewEditEventArgs e)
{
try
{
tab0.Enabled = false;
tab1.Enabled = true;
grd_Master.EditIndex = e.NewEditIndex;
GridViewRow rw = (GridViewRow)grd_Master.Rows[e.NewEditIndex];
Label CoolingCode = (Label)rw.FindControl("Cooling_Code");
Label ProdgrpCode = (Label)rw.FindControl("lblProdGrpCode");
Label SubProdCode = (Label)rw.FindControl("lblSubProdGrpCode");
Label MakeCode = (Label)rw.FindControl("lblMakeCode");
Label ReferCode = (Label)rw.FindControl("lblRegerCode");
Label CompressoreCode = (Label)rw.FindControl("lblCompressorCode");
Label CoolingName = (Label)rw.FindControl("lblCoolingName");
Label CoolingName_Short = (Label)rw.FindControl("lblCoolingShortName");
Label CoolingName_Desc = (Label)rw.FindControl("lblCoolingDescr");
Label lblFilePath = (Label)rw.FindControl("lblFilePath");
txtCoolType.Text = CoolingName.Text.Trim();
txtCoolTypeShortname.Text = CoolingName_Short.Text.Trim();
txtCoolTypeDescrip.Text = CoolingName_Desc.Text.Trim();
ddlProdGrp.SelectedValue = ProdgrpCode.Text;
ddlSubProd.SelectedValue = SubProdCode.Text;
ddlMake.SelectedValue = MakeCode.Text;
ddlCompressor.SelectedValue = CompressoreCode.Text;
ddlRefe.SelectedValue = ReferCode.Text;
btnsave.Text = "Update";
ViewState["CoolingCode"] = CoolingCode.Text;
TabContainer_Item.ActiveTabIndex = 1;
Session["CoolingCode"] = CoolingCode.Text;
this.fu1.BindGridDoc();
}
catch (Exception ex)
{
Master.ErrorMessage(ex.Message);
}
}
protected void txt_Search_TextChanged(object sender, EventArgs e)
{
try
{
DataSet ds = gn.ExecuteDataset("Search_CoolingType", txt_Search.Text.Trim());
ViewState["CoolingTypeData"] = ds.Tables[0];
if (ds.Tables[0].Rows.Count == 0)
{
FillEmptyGrid();
}
else
{
grd_Master.DataSource = ds;
grd_Master.DataBind();
}
}
catch (Exception ex)
{
Master.ErrorMessage(ex.Message);
}
}
You need to make sure that the grid has focus. The initial click is likely just setting focus on the grid, and then it sees the second click as starting your edit.
A simple ActiveControl = grd_Master; at the end of the txt_Search_TextChanged event should do the trick.

Change Gridview column widths dynamically in edit mode

I have a gridview that can have 1 or 2 controls displayed in 1 column when in edit mode depending on the selection of a dropdown in another column. One control is a textbox the other a label. I have the textbox first and the label beside the textbox after it. My problem is when the textbox and label are showing, the label's text extends into the next column. I would like the column width to be as wide as the controls displayed.
How can I do this?
This is my markup for the grid:
<div id="DeviceGridWrapper">
<asp:TextBox ID="RecipientID" runat="server" Visible="false"> </asp:TextBox>
<asp:GridView ID="DeviceInfoGridView" runat="server"
AutoGenerateColumns="False" Caption="Device Information"
CaptionAlign="Top" CssClass="grid" RowStyle-Wrap="true"
HorizontalAlign="Left" ShowFooter="True" PageSize="5"
ShowHeaderWhenEmpty="False"
OnRowCancelingEdit="DeviceInfoGridView_RowCancelingEdit"
OnRowDataBound="DeviceInfoGridView_RowDataBound"
OnRowDeleting="DeviceInfoGridView_RowDeleting"
OnRowEditing="DeviceInfoGridView_RowEditing"
OnRowUpdating="DeviceInfoGridView_RowUpdating" AllowPaging="True"
ondatabound="DeviceInfoGridView_DataBound"
onrowcommand="DeviceInfoGridView_RowCommand">
<Columns>
<asp:TemplateField HeaderText="Device ID">
<ItemTemplate>
<asp:Label ID="digvLblDeviceID" runat="server" Text='<%# Bind("DeviceID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Device" ItemStyle-Wrap="false">
<ItemTemplate>
<asp:Label ID="digvLblDeviceName" runat="server" Text='<%# Bind("DeviceName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="digvEditDeviceName" runat="server" Visible="false" Text='<%# Bind("DeviceName") %>'></asp:Label>
<asp:DropDownList ID="digvDDListDeviceName" runat="server" ClientIDMode="Static"
data-placeholder="Choose device…" class="chosen-single"></asp:DropDownList>
<asp:RequiredFieldValidator ID="ReqValueDDLDeviceNameEdit" runat="server"
ControlToValidate="digvDDListDeviceName" ValidationGroup="EditDeviceValidation"
ErrorMessage="Selection required." CssClass="message-error-dropdown">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="digvDDListDeviceNameInsert" runat="server" ClientIDMode="Static"
data-placeholder="Choose device…" class="chosen-single">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="ReqValueDDLDeviceNameInsert" runat="server" InitialValue="0"
ControlToValidate="digvDDListDeviceNameInsert" ValidationGroup="InsertDeviceValidation"
ErrorMessage="Selection required." CssClass="message-error-dropdown">
</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Service Provider">
<ItemTemplate>
<asp:Label ID="digvLblServiceName" runat="server" Text='<%# Bind("ServiceName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="digvEditServiceName" runat="server" Visible="false" Text='<%# Bind("ServiceName") %>'></asp:Label>
<asp:DropDownList ID="digvDDListServiceName" runat="server" ClientIDMode="Static"
OnSelectedIndexChanged="DeviceInfoGridView_SelectedIndexChanged_EditServiceName" AutoPostBack="true" EnableViewState="true"
data-placeholder="Choose service…" class="chosen-single"></asp:DropDownList>
<asp:RequiredFieldValidator ID="ReqValueDDLServiceNameEdit" runat="server"
ControlToValidate="digvDDListServiceName" ValidationGroup="EditDeviceValidation"
ErrorMessage="Selection required." CssClass="message-error-dropdown">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="digvDDListServiceNameInsert" runat="server" ClientIDMode="Static" Enabled="false"
data-placeholder="Choose service…" class="chosen-single">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="ReqValueDDLServiceNameInsert" runat="server" InitialValue="0"
ControlToValidate="digvDDListServiceNameInsert" ValidationGroup="InsertDeviceValidation"
ErrorMessage="Selection required." CssClass="message-error-dropdown">
</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address">
<ItemTemplate>
<asp:Label ID="digvLblAddress" runat="server" Text='<%# Bind("Address") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="digvTxtBoxAddress" runat="server" Text='<%# Bind("Address") %>' Width="50%" ClientIDMode="Static"></asp:TextBox>
<asp:Label ID="digvEditAddressExt" runat="server" Visible="false" Text='<%# Bind("ServiceExtension") %>' Width="40%"
ClientIDMode="Static"></asp:Label>
<asp:RequiredFieldValidator ID="ReqValueAddressEdit" runat="server"
ControlToValidate="digvTxtBoxAddress" ValidationGroup="EditDeviceValidation"
ErrorMessage="Required field." CssClass="message-error">
</asp:RequiredFieldValidator>
<asp:CustomValidator ID="CustomValAddressEdit" runat="server" ControlToValidate="digvTxtBoxAddress" CssClass="message-error"
ErrorMessage="*" ClientValidationFunction="ValidateAddressEdit" EnableClientScript="true"
ValidationGroup="EditDeviceValidation" ></asp:CustomValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="digvTxtBoxAddressInsert" runat="server" ClientIDMode="Static"></asp:TextBox>
<asp:RequiredFieldValidator ID="ReqValueAddressInsert" runat="server"
ControlToValidate="digvTxtBoxAddressInsert" ValidationGroup="InsertDeviceValidation"
ErrorMessage="Required field." CssClass="message-error">
</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Active">
<ItemTemplate>
<asp:Label ID="digvLblActive" runat="server" Text='<%# (Boolean.Parse(Eval("Active").ToString())) ? "Yes" : "No" %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="digvDDListActive" runat="server" Text='<%# (Boolean.Parse(Eval("Active").ToString())) ? "Yes" : "No" %>'>
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="digvDDListActiveInsert" runat="server">
<asp:ListItem Selected="True">Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action" ShowHeader="False" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Button ID="digvEditButton" runat="server" CausesValidation="True" CommandName="Edit"
Text="Edit" CssClass="gridActionbutton" ValidationGroup="EditDeviceValidation">
</asp:Button>
<asp:Button ID="digvDeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
Text="Delete" CssClass="gridActionbutton" OnClientClick="return confirm('Are you sure you want to delete this Device Information?')" >
</asp:Button>
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="digvUpdateButton" runat="server" CausesValidation="True" ValidationGroup="EditDeviceValidation" CommandName="Update"
Text="Update" CssClass="gridActionbutton"></asp:Button>
<asp:Button ID="uigvCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel" CssClass="gridActionbutton"></asp:Button>
</EditItemTemplate>
<FooterTemplate>
<asp:Button ID="digvAddButton" runat="server" CommandName="Add" Text="Add Device" Width="90%" CausesValidation="true"
CssClass="gridActionbutton" ValidationGroup="InsertDeviceValidation">
</asp:Button>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<tr>
<th>Device ID</th>
<th>Device</th>
<th>Service Provider</th>
<th>Address</th>
<th>Active</th>
<th>Action</th>
</tr>
<tr>
<td colspan="7" style="text-align:center;">
No Devices were found for you. Devices can be added by clicking the 'Add Device' Button.
</td>
</tr>
<tr>
<td></td>
<td>
<asp:DropDownList ID="digvDDListDeviceNameInsert" runat="server" ClientIDMode="Static"
data-placeholder="Choose device…" class="chosen-single">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="ReqValueDDLDeviceNameEmpty" runat="server" InitialValue="0"
ControlToValidate="digvDDListDeviceNameInsert" ValidationGroup="InsertDeviceValidationEmpty"
ErrorMessage="Selection required." CssClass="message-error-dropdown">
</asp:RequiredFieldValidator>
</td>
<td>
<asp:DropDownList ID="digvDDListServiceNameInsert" runat="server" ClientIDMode="Static" Enabled="false"
data-placeholder="Choose service…" class="chosen-single">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="ReqValueDDLServiceNameEmpty" runat="server" InitialValue="0"
ControlToValidate="digvDDListServiceNameInsert" ValidationGroup="InsertDeviceValidationEmpty"
ErrorMessage="Selection required." CssClass="message-error-dropdown">
</asp:RequiredFieldValidator>
</td>
<td>
<asp:TextBox ID="digvTxtBoxAddressInsert" runat="server" ClientIDMode="Static"></asp:TextBox>
<asp:RequiredFieldValidator ID="ReqValueAddressEmpty" runat="server"
ControlToValidate="digvTxtBoxAddressInsert" ValidationGroup="InsertDeviceValidationEmpty"
ErrorMessage="Required field." CssClass="message-error">
</asp:RequiredFieldValidator>
</td>
<td>
<asp:DropDownList ID="digvDDListActiveInsert" runat="server">
<asp:ListItem Selected="True">Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:Button ID="digvAddButtonEmpty" runat="server" CommandName="Add" Text="Add Device" Width="90%" CausesValidation="true"
CssClass="gridActionbutton" ValidationGroup="InsertDeviceValidationEmpty">
</asp:Button>
</td>
</tr>
</EmptyDataTemplate>
</asp:GridView>
</div>
This is my current styling of the grid:
.grid
{background-color: #fff;
border: solid 2px #000;
border-collapse:collapse;
color: #FFF; overflow:auto
}
.grid td {
padding-left: 5px;
color: #000;
font-size: medium;
}
.grid th {
color: #000;
background: #99C3BB;
font-size: medium;
font-weight: bold;
}
.grid caption {
color: #000;
text-align:center;
font-weight:bold;
font-size:1.2em;
padding: 2px;
background-color: #99C3BB;
border: 2px solid black;
}
.grid table tr td {
color: #000;
font-size: small;
padding: 5px;
}
#DeviceGridWrapper
{
height: 250px;
width: 100%;
padding-bottom: 10px;
}
The column that is the problem is the 'Address' column. When only the textbox shows the width is set to '90%' programmatically. When the textbox and label are shown, the textbox is set to '50%' and the label is '40%'. They are side-by-side which is what I want. I need the Address column to widen to accomodate both of the controls so that the label does not extend into the next column.
Is there a way to set the Address column to a width that accomodates both controls?
Thanks.
Try using <EditRowStyle> element to the GridView::
<asp:GridView ID="GridView1" runat="server">
<EditRowStyle BackColor="Red" Width="100%" />
</asp:GridView>

GridView Textboxes not getting cleared on web tab change

I have a Page which has a 2 level web tab . The Content tabs FIXED and VARIABLE in turn has a web tab. This web tab is loaded with a User control which has a gridview.
My problem is the textboxes in the Gridview are not cleared on going from one sub tab to next sub tab . I tried all possible methods :
1.Bind grid to null ( datasource and DatasoruceId )
2. grid dispose
3. grid columns clear
No luck !!!.. HELP!!!
Note : I am modifying the data in the textboxes from javascript.
<ig:Webtab id="wi" runat="server" width="938px" displaymode="Scrollable" meta:resourcekey="wtabInvestmentTypeResource1">
<ClientEvents SelectedIndexChanging="webTab_SelectedIndexChanging" />
<AutoPostBackFlags SelectedIndexChanged="On" />
<Tabs>
<ig:ContentTabItem runat="server" Text="Variable Investment Type" meta:resourcekey="ContentTabItemResource1">
<Template>
<div class="clear vspacesmall hspacenarrow">
</div>
<ig:WebTab ID="wv" runat="server" Width="908px" DisplayMode="Scrollable" ClientIDMode="Static"
meta:resourcekey="wtabVariableResource1">
<ClientEvents SelectedIndexChanging="webTab_SelectedIndexChanging" />
<AutoPostBackFlags SelectedIndexChanged="On" />
</ig:WebTab>
</Template>
</ig:ContentTabItem>
<ig:ContentTabItem runat="server" Text="Fixed Investment Type" meta:resourcekey="ContentTabItemResource2">
<Template>
<div class="clear vspacesmall hspacenarrow">
</div>
<ig:WebTab ID="wf" runat="server" Width="908px" DisplayMode="Scrollable" class="tabs"
meta:resourcekey="wtabFixedResource1">
<ClientEvents SelectedIndexChanging="webTab_SelectedIndexChanging" />
<AutoPostBackFlags SelectedIndexChanged="On" />
</ig:WebTab>
The web tab loads a user control which has the following gridview :
<div class="clear vspacesmall gridtablearea scrollPanel-horizontal Contol-Max-Height">
<asp:UpdatePanel ID="upBuyMultipleGetDiscount" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="gvInvestmentDetails" runat="server" OnRowDataBound="gvInvestmentDetails_RowDataBound"
TabIndex="5" AutoGenerateColumns="False" CssClass="gridtable scrollPanel-horizontal" Width="100%" meta:resourcekey="gvInvestmentDetails_DefaultResource1"
EnableViewState="true" ViewStateMode="Enabled" ShowFooter="true" OnRowCommand="gvInvestmentDetails_Row_Command">
<Columns>
<asp:BoundField DataField="InvestmentTypeId" />
<asp:BoundField DataField="CustomerCombinationId" />
<asp:BoundField DataField="ProductId" />
<asp:TemplateField HeaderText="Account" ItemStyle-Width="100px" meta:resourcekey="Account">
<ItemTemplate>
<asp:Label ID="lblAccountName" runat="server" Text='<%# Eval("CustomerCombinationName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Products" ItemStyle-Width="200px" meta:resourcekey="Products">
<ItemTemplate>
<asp:Label ID="lblProductName" runat="server" Text='<%# Eval("ProductName") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTotal" CssClass="fRight boldText" ForeColor="#656565" runat="server" Text='TOTAL :' meta:resourcekey="lblTotal"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Phase Investment Amount" meta:resourcekey="PhaseInvestmentAmount" >
<ItemTemplate>
<asp:Repeater ID="rptrPhases" runat="server" ClientIDMode="Static" OnDataBinding="rptrPhases_OnDataBinding">
<ItemTemplate>
<div style="float: left; padding: 4px;">
<table id="PhaseDetails">
<tr>
<td>
<tr>
<asp:Label ID="lblPhaseID" runat="server" Text='<%# Eval("PhaseID") %>' Visible="False"></asp:Label>
<asp:Label ID="lblPhaseName" Class="vspacesmall" runat="server" Text='<%# Eval("PhaseName") %>' ></asp:Label><br />
<asp:TextBox ID="txtPhaseAmount" runat="server" Text='<%# Eval("PhaseAmount", "{0:F2}") %>' CssClass="tar"
ClientIDMode="Static" Width="80px" MaxLength="27" onpaste="return false;" ViewStateMode="Enabled"
meta:resourcekey="txtPhaseAmount"></asp:TextBox>
</tr>
<tr>
<asp:Label ID="lblUsageAmount" runat="server" Visible="false" Text='<%# Eval("PhaseUpdateAmount", "{0:F2}") %>'></asp:Label>
</tr>
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
<FooterTemplate>
<asp:Repeater ID="rptTotalAmount" runat="server" ClientIDMode="Static">
<ItemTemplate>
<div style="float: left; padding: 4px;">
<table>
<tr>
<td>
<asp:TextBox ID="txtPhaseTotal" Text='<%# Eval("PhaseAmount", "{0:F2}") %>' Width="80px" CssClass="tar boldText"
ForeColor="#656565" runat="server" ViewStateMode="Enabled" ClientIdMode="Static" autocomplete="off" ></asp:TextBox>
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:Repeater>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Roles" ItemStyle-Width="150px" meta:resourcekey="Roles">
<ItemTemplate>
<asp:CheckBoxList ID="chckRoleList" runat="server" DataTextField="RoleName"
DataValueField="RoleId" EnableViewState="true" ViewStateMode="Enabled" onclick="checkBoxLstChanged(this.id,'chkSelectAll');SetIsChanged('1');">
</asp:CheckBoxList>
<asp:RadioButtonList ID="rdbRoleList" runat="server" DataTextField="RoleName"
DataValueField="RoleId" EnableViewState="true" ViewStateMode="Enabled">
</asp:RadioButtonList>
</ItemTemplate>
<FooterTemplate>
<asp:CheckBox ID="chckSelectAll" runat="server" Text="Select All" onclick="setAllCheckBoxes('chckRoleList',this);SetIsChanged('1');" meta:resourcekey="chckSelectAll">
</asp:CheckBox>
<br>
<asp:Button ID="btnRemove" runat="server" CssClass="btnStyle fLeft" Text="Remove" OnClientClick="return ValidateRemoveRoles('gvInvestmentDetails')"
CommandName="RemoveRoles" CommandArgument='<%# Container.DataItemIndex %>'
meta:resourcekey="btnRemove" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="InvestmentAmount" meta:resourcekey="InvestmentAmount">
<ItemTemplate>
<asp:TextBox ID="txtInvAmt" Width="80px" runat="server" Text='<%# Eval("InvestmentAmount","{0:F2}") %>'
ClientIdMode="Static" ViewStateMode="Enabled" CssClass="fRight tar boldText" ></asp:TextBox >
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtTotalInvestment" ClientIdMode="Static" Width="80px" ViewStateMode="Enabled" CssClass="fRight tar boldText " ForeColor="#656565" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField DataField="RecordStatus" />
</Columns>
<%-- <FooterStyle HorizontalAlign="Left" CssClass="boldText" ForeColor="#656565" />--%>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
The back end code for loading the USer control :
private void LoadInvestmentDetails(int investmentTypeId, WebTab currentWebTab, int tabIndex)
{
Panel panel = GetPanelToBeLoaded(investmentTypeId);
if (currentWebTab.Tabs[tabIndex].Controls.Count == 0)
{
currentWebTab.Tabs[tabIndex].Controls.Add(panel);
budgetDetailsControl.Initialize(investmentTypeId);
budgetDetailsControl.InvestmentDetailsSaved += new ProjectInvestmentDetailsSavedEventHandler(BudgetDetailsControl_BudgetDetailsSaved);
PreviouslyLoadedTab = int.Parse(currentWebTab.Tabs[currentWebTab.SelectedIndex].UserControlUrl);
}
// other code
}
private Panel GetPanelToBeLoaded(int investmentTypeId)
{
System.Web.UI.Control userControl = GetInvestmentDetailsUserControlUrl();
Panel panel = new Panel();
panel.Controls.Add(userControl);
budgetDetailsControl = (IProjectInvestmentDetailsControl)userControl;
budgetDetailsControl.InvestmentTypeID = investmentTypeId;
return panel;
}
private System.Web.UI.Control GetInvestmentDetailsUserControlUrl()
{
return LoadControl(ProjectCommonKeys.URL_PROJECT_BUDGET_DETAILS);
}
The Usercontrol implments the IprojectInvestmentDetails interface and the initalize function of the UC is called first for the binding etc
I figured out the problem. Each user control bound to the sub tab shud be given a unique Id..or else even if we bind new data the data from the earlier instance will persist.
.
private Panel GetPanelToBeLoaded(int investmentTypeId)
{
System.Web.UI.Control userControl = GetInvestmentDetailsUserControlUrl();
**userControl.ID = investmentTypeId.ToString();**
Panel panel = new Panel();
panel.Controls.Add(userControl);
projectInvestmentDetailsControl = (IProjectInvestmentDetailsControl)userControl;
projectInvestmentDetailsControl.InvestmentTypeID = investmentTypeId;
projectInvestmentDetailsControl.UserContext = userContext;
projectInvestmentDetailsControl.PlanningWizardDataManager = PlanningWizardDataManager;
projectInvestmentDetailsControl.PlanningServiceWrapper = PlanningServiceWrapper;
return panel;
}`
Thanks fr the help...

How do I change the forecolor of a control in a .NET Grid View?

How do I access a control in a grid view so that I can change it's forecolor? In this code below, FindControl() returns null.
protected void mileageRowBound(object sender, GridViewRowEventArgs e)
{
(e.Row.Cells[1].FindControl("ddlStateCode") as DropDownList).ForeColor = System.Drawing.Color.LightBlue;
}
I have also tried e.Row.FindControl("ddlStateCode") and a few other variations. I'm stumped.
Someone asked for the markup:
<asp:GridView runat="server" OnPreRender="grvStateWiseMileage_OnPreRender" OnRowCommand="grvStateWiseMileage_OnRowCommand"
CssClass="GridViewStyle" BorderWidth="1" Width="100%" ID="grvStateWiseMileage"
AutoGenerateColumns="false" RowStyle-Height="25px" ShowHeader="false" OnRowDataBound="mileageRowBound">
<Columns>
<asp:TemplateField>
<ItemStyle CssClass="GridViewRowStyle" Width="5%" />
<ItemTemplate>
<asp:Label ID="lblLine" runat="server" onKeyUp="javascript:ValidateDecimal(this)"
Text='<%# Eval("Line#") %>'></asp:Label>
<asp:ImageButton runat="server" ID="imgbtnMileageDelete" ImageUrl="Images/delete.png" />
<asp:HiddenField runat="server" ID="hdnFuelMileageCode" Value='<% #Eval("FuelMileageCode") %>' />
<asp:HiddenField runat="server" ID="hdnMileageCode" Value='<% # Eval("MileageCode") %>' />
<asp:HiddenField runat="server" ID="hdnMileagePosted" Value='<% # Eval("MileagePosted") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle CssClass="GridViewRowStyle" Width="10%" />
<ItemTemplate>
<asp:DropDownList runat="server" OnLoad="ddlStateCode_OnLoad" ID="ddlStateCode" Style="border: none;
border-width: 0px; width: 100px">
</asp:DropDownList>
<asp:HiddenField runat="server" ID="hdnStateCode" Value='<% # Eval("State")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle CssClass="GridViewRowStyle" Width="10%" />
<ItemTemplate>
<BDP:BasicDatePicker ID="bdpMileageDate" runat="server">
</BDP:BasicDatePicker>
<asp:HiddenField runat="server" ID="hdnMileageDate" Value='<% # Eval("Date")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle CssClass="GridViewRowStyle" Width="10%" />
<ItemTemplate>
<asp:TextBox ID="txtMiles" Style="border: none; border-width: 0px; text-align: right"
Width="90%" runat="server" MaxLength="12" onKeyUp="javascript:ValidateDecimal(this)"
Text='<%# Eval("Miles") %>' onblur="postBackHiddenField('hdnStateWiseMileage')"
onkeydown="return postBackHiddenFieldForEnterMiles(event)"></asp:TextBox>
<cc1:FilteredTextBoxExtender runat="server" FilterMode="ValidChars" FilterType="Custom, Numbers"
ValidChars="." TargetControlID="txtMiles">
</cc1:FilteredTextBoxExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle CssClass="GridViewRowStyle" Width="10%" />
<ItemTemplate>
<asp:DropDownList runat="server" ID="ddlLoadStatus" Style="border: none; border-width: 0px;
width: 100px">
<asp:ListItem Selected="True" Text="Loaded" Value="1"></asp:ListItem>
<asp:ListItem Text="Empty" Value="2"></asp:ListItem>
<asp:ListItem Text="Toll" Value="3"></asp:ListItem>
</asp:DropDownList>
<asp:HiddenField runat="server" ID="hdnMileageType" Value='<% # Eval("LoadStatus")%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BorderStyle="None" BackColor="White" />
</asp:GridView>
Try to wrap your line of code in
if(e.Row.RowType == DataControlRowType.DataRow)
{
(e.Row.FindControl("ddlStateCode") as DropDownList).ForeColor = System.Drawing.Color.LightBlue;
}
So it will skip header (and footer and a few others).
I guess the better answer to this question is use CSS to change the color of the control text.
Try add the following lines to the ASPX page.
<style type="text/css">
#ddlStateCode
{
color: #FF0000; /* Change to the hexacode you want */
}
</style>
Hope it helps.

Categories

Resources