How to check atleast one checkbox is checked? - c#

I have ascx page in that I have a grid in side that I have added radio button, I want to check at least one checkbox should be checked before unload the page or clicking on btn save.
<asp:GridView ID="grdTest" runat="server" DataKeyNames="Id" AutoGenerateColumns="False" HorizontalAlign="Center" GridLines="None" onrowcreated="grdTest_RowCreated">
<asp:TemplateField >
<ItemTemplate>
<asp:TextBox ID="txtText" Rows="10" Columns="40" runat="server" TextMode="MultiLine" Height="55px" Text='<%# Eval("Text") %>'></asp:TextBox>
<asp:Button ID="btnSave" runat="server" Text="Save" CommandName="Save"/>
<span id="checkbox">
<asp:RadioButton ID="rbtnTest" runat="server" Checked='<%# Eval("Correct") %>' TextAlign="Left" Height="28px" />
</span>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtText" Rows="10" Columns="40" runat="server" TextMode="MultiLine" />
<asp:Button ID="btnSave" runat="server" Text="Save" CommandName="Save"/>
<asp:CheckBox ID="rbtnTest" runat="server" Enabled="true" TextAlign="Left"/>
</EditItemTemplate>
</asp:TemplateField>
</asp:GridView>
How is this possible plz some one help me?

<script type="text/javascript" language="javascript">
function Validate_Checkbox()
{
var chks=document.getElementsByTagName('input');
var hasChecked = false;
for (var i = 0; i < chks.length; i++)
{
if (chks[i].checked)
{
hasChecked = true;
break;
}
}
if (hasChecked == false)
{
alert("Please select at least one checkbox..!");
return false;
}
return true;
}
</script>
and on Submit Button you have to write
OnClientClick="return Validate_Checkbox()"

Related

I am trying to close modelpopupextender using a button click, this button belongs to another form so modelpopupextender is not able to access it

I am trying to close modelpopupextender using a button click, this button belongs to another form so modelpopupextender is not able to accessable.
I have tried to remove the updatepanel as suggested, but it's not working.
This is my form1.aspx (which includes a button, onclick which will display a ModalPopupExtender in which includes grid view)
<asp:Button id="btnclick" text="Show Modal Popup" runat="server" >
</asp:Button>
<cc1:ModalPopupExtender ID="ModelPopupExtender1" runat="server"
PopupControlID="pc" TargetControlID="btnclick" OkControlID ="Button2"
CancelControlID="Button1" BackgroundCssClass="bcc" BehaviorID="MPE1">
</cc1:ModalPopupExtender>
<asp:Panel ID="pc" runat="server" CssClass="pop" Style="display:none;">
<iframe style="width:1003px;height:550px;" id="if"src="EstPopUp.aspx" runat="server"></iframe>
</asp:Panel>
This is my EstPopUp.aspx ( Where gridview is dislpayed with save and cancel buttons)
<asp:GridView ID="gvContacts" runat="server" AutoGenerateColumns="false" CellPadding="5" DataKeyNames="EstimateBreakUpTypeId" OnSelectedIndexChanged="gvContacts_SelectedIndexChanged" OnRowDataBound="gvContacts_RowDataBound" >
<Columns>
<asp:TemplateField HeaderText="DispOrder">
<ItemTemplate>
<center>
<asp:TextBox ID="TextBox1" width="20px" runat="server" Text='<%#
Bind("DispOrder") %>'></asp:TextBox>
</center>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="EstBreakUpName">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" ></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Percentage(%)">
<ItemTemplate>
<center>
<asp:TextBox ID="TextBox2" Width="30px" runat="server"></asp:TextBox>
</center>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<ItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" CssClass="sum" ></asp:TextBox>
<cc1:FilteredTextBoxExtender ID="fte" runat="server" Enabled="true"
TargetControlID="TextBox3" FilterType="Numbers,Custom" ValidChars=".">
</cc1:FilteredTextBoxExtender>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br/>
<asp:Button ID="Button1" runat="server" Text="Save" OnClick="Button1_Click"></asp:Button>
<asp:Button class="abc" ID="Button2" runat="server" Text="Cancel" CssClass=".cancel" OnClick="Button2_Click1"></asp:Button >
<br />
</asp:GridView>
My expected result is, when cancel button is clicked the modelpopup should disappear.
Try this, it works fine.
protected void Button2_Click(object sender, EventArgs e)
{
string url = " form1.aspx";
Response.Write("<script>top.location='" + url + "';parent.location='" + url + "';</script>");
}

website gridview not working at iis on azure

Good day everyone, I've a problem with the published web app when posting it at azure
so, my code is like 2 pages, one for the datalist, the other one is for input page
the problematic page is containing a gridview with a templatefield that contains 2 image buttons
one is for display block another div and fills the grid within
the other one is for redirect to input page with some session update for flagging the transaction is either new or editing
the problem is, my gridview_rowcommand method is working locally either on quick debugging (IIS Express) or run it via IIS
but when I publish it at azure, the rowcommand not functioning at all
below are some codes
<div class="divWrapperGrid" style="border-top:none;">
<div class="divContentGrid" style="min-height:190px;">
<asp:Button ID="btnChange" runat="server" Text="Button" Style="display:none;" OnClick="btnChange_Click"/>
<asp:UpdatePanel runat="server" ID="upWHOrder">
<ContentTemplate>
<asp:GridView ID="dgWHOrder" runat="server" AutoGenerateColumns="false" AllowPaging="true" ShowHeaderWhenEmpty="true"
CssClass="data-grid" HeaderStyle-CssClass="data-grid-header" RowStyle-CssClass="data-grid-row" EmptyDataRowStyle-CssClass="data-grid"
GridLines="None" EmptyDataText="There is no data"
OnRowDataBound ="dgWHOrder_RowDataBound" OnRowCommand="dgWHOrder_RowCommand">
<EmptyDataTemplate>
<asp:Label ID="Label2" CssClass="no-data-grid" runat="server">No records found!</asp:Label>
</EmptyDataTemplate>
<Columns>
<asp:TemplateField HeaderStyle-CssClass="hidden-column" ItemStyle-CssClass="hidden-column">
<EditItemTemplate>
<asp:Label ID="laID" runat="server" Text='<%#Eval("ID")%>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="laID" runat="server" Text='<%#Eval("ID")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="WarehouseOrderNo" />
<asp:BoundField DataField="OrderDateStr" />
<asp:BoundField DataField="TotalItem" />
<asp:BoundField DataField="Responsible" />
<asp:BoundField DataField="MerchantCode" />
<asp:TemplateField ItemStyle-Width="35%" ItemStyle-HorizontalAlign="Right">
<EditItemTemplate>
<asp:ImageButton ID="btnSave" runat="server" CommandName="save" CommandArgument="<%#((GridViewRow) Container).RowIndex %>" ImageUrl="~/images/save-icon.png" Width="20px" Height="20px" ToolTip="Save" OnClientClick="return true;" />
<asp:ImageButton ID="btnCancel" runat="server" CommandName="cancel" CommandArgument="<%#((GridViewRow) Container).RowIndex %>" ImageUrl="~/images/cancel-icon.png" Width="20px" Height="20px" ToolTip="Cancel" OnClientClick="return true;" />
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton ID="btnEdit" runat="server" CommandName="edit" CommandArgument="<%#((GridViewRow) Container).RowIndex %>" ImageUrl="~/images/edit-icon.png" Width="20px" Height="20px" ToolTip="Update" OnClientClick="return true;" />
<asp:ImageButton ID="btnView" runat="server" CommandName="view" CommandArgument="<%#((GridViewRow) Container).RowIndex %>" ImageUrl="~/images/delete-xxl.png" Width="20px" Height="20px" ToolTip="View" OnClientClick="return true;" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
btnEdit is the redirect processing one
btnView is for the view processing one
and the gridview_rowcommand method
protected void dgWHOrder_RowCommand(object sender, GridViewCommandEventArgs e)
{
int rowIndex = 0;
rowIndex = Convert.ToInt32(e.CommandArgument);
string script = string.Empty;
int HeaderID = 0;
if (rowIndex > -1)
{
GridViewRow row = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
HeaderID = Convert.ToInt32(((Label)row.FindControl("laID")).Text);
}
BPWarehouseOrder objBP = new BPWarehouseOrder();
BOSearch objSrc = new BOSearch();
switch (e.CommandName)
{
case "edit":
IsEdit = true;
EditItemHeader = (from a in ListHeader
where a.ID == HeaderID
select a).Single();
Response.Redirect("WarehouseOrderIns.aspx");
break;
case "view":
List<BOWarehouseOrderDatail> objDt = new List<BOWarehouseOrderDatail>();
objBP = new BPWarehouseOrder();
objSrc = new BOSearch();
objSrc.FieldName = "IDWarehouseOrder";
objSrc.FieldValue = HeaderID.ToString();
objSrc.SearchType = "Equal";
objDt = objBP.GetDetailList(objSrc);
if (objBP.MsgCode != 0)
{
script += " alert('" + objBP.MsgDesc + #"');
";
ScriptManager.RegisterClientScriptBlock(this, GetType(), Guid.NewGuid().ToString(), script, true);
return;
}
dgOrderDetail.DataSource = objDt;
if (objDt.Count > 0)
{
dgOrderDetail.PageSize = objDt.Count;
}
dgOrderDetail.DataBind();
script += #" document.getElementById('popup').style.display = 'block';
";
ScriptManager.RegisterClientScriptBlock(this, GetType(), Guid.NewGuid().ToString(), script, true);
break;
}
}
TLDR: publishing website at azure, gridview_rowcommand function not working at azure, but working at local
Regards
Mediocre Programmer
I create the following sample using ASP.NET GridView control inside a UpdatePanel control, it works fine on my Azure web app service, OnRowCommand of the GridView control can be executed as expected.
GridView inside UpdatePanel
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="my_testgrid" runat="server" AutoGenerateColumns="false" OnRowCommand="my_testgrid_RowCommand">
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label runat="server" Text='<%#Eval("ID")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label runat="server" Text='<%#Eval("Name")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="select" CommandName="select" CommandArgument="<%#((GridViewRow) Container).RowIndex %>" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
Specify data source in Page_Load event
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("Name");
dt.Rows.Add("u001", "jack");
dt.Rows.Add("u002", "fred");
my_testgrid.DataSource = dt;
my_testgrid.DataBind();
}
}
OnRowCommand event
protected void my_testgrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "select")
{
string arg = e.CommandArgument.ToString();
}
}
Browse the web app
OnRowCommand event can be executed if click [select] button
To troubleshot the issue, you can try to remote debug your web app and check if something wrong with your code.

how use jQuery Countdown plugin in a GridView

i want to use this jQuery Countdown plugin : http://keith-wood.name/countdown.html in a Gridview ! every row has a DeadLine time that is bind from Database , i dont have any idea how to bind these dates !! look at this codes :
<script>
$(function () {
var austDay = new Date();
austDay = new Date(2014, 8, 10); // the count down date !
$('#defaultCountdown').countdown({until: austDay});
});
</script>
<div id="defaultCountdown"></div> // count down will be shown here !
and its my gridview
<asp:GridView ID="GroupExsGridView" Width="100%"
BorderWidth="0" runat="server">
<Columns>
<asp:TemplateField>
<ItemStyle BorderWidth="0" />
<ItemTemplate >
<div class="alert alert-info" role="alert">
<asp:Label CssClass="h5" ID="Exsddeadline" runat="server" Text='<%# Bind("GDeadLine") %>'></asp:Label><br /><br />
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
i solved my question ! look at codes below !
<asp:GridView ID="GroupExsGridView" Width="100%"
BorderWidth="0" ShowFooter="false" DataKeyNames="GroupExsID" OnRowDataBound="GroupExsGridView_RowDataBound" ShowHeader="false" EmptyDataText="هیچ تمرینی موجود نیست" AutoGenerateColumns="false" AllowPaging="false" AllowSorting="false" PageSize="50" runat="server">
<Columns>
<asp:TemplateField>
<ItemStyle BorderWidth="0" />
<ItemTemplate >
<div class="alert alert-info" role="alert">
<asp:Label ID="ExsName" CssClass="h4" Text='<%# Bind("GExsName") %>' runat="server" ></asp:Label><br />
<asp:Label CssClass="h5" ID="ExsdES" style="word-wrap:break-word;" runat="server" Text='<%# Bind("GExsDes") %>'></asp:Label><br /><br />
<div class="defaultCountdown" id="defaultCountdown" runat="server"></div>
<asp:Label ID="ExsDeadLine" style="display:none" runat="server" Text='<%# Bind("GExsDeadLine")%>'></asp:Label>
</div>
<asp:HyperLink ID="DownloadLink" Target="_blank" NavigateUrl='<%# Bind("GExsFilePath") %>' CssClass=" btn btn-lg btn-link pull-left" runat="server">دانلود</asp:HyperLink>
<asp:LinkButton ID="DeleteExs" CssClass=" btn btn-lg btn-link pull-left" OnClick="DeleteExs_Click" runat="server">حذف</asp:LinkButton>
<asp:Label ID="HelpText" CssClass="small" runat="server" Text="تاریخ ارسال:"></asp:Label>
<asp:Label ID="ExsDate" CssClass="small" runat="server" Text='<%# fbTime( (DateTime)Eval("GExsDate") ) %>'></asp:Label>
<hr />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<script>
$(function () {
var gridview = document.getElementById("<%= GroupExsGridView.ClientID %>");
for (i = 0; i < gridview.rows.length; i++) {
var la = document.getElementById("ContentPlaceHolder1_GroupExsGridView_ExsDeadLine_" + i);
var austDay = new Date(la.innerHTML);
$('#ContentPlaceHolder1_GroupExsGridView_defaultCountdown_' + i).countdown({ until: austDay });
}
});

Adding a warning message to an aspx page

I have an asp.net application in which i have to add a warning javascript message when i click into button in my Gridview:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:HiddenField ID="Ref" runat="server" value='<%#Eval("Ref")%>' ></asp:HiddenField>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Button ID="Savebtn" runat="server" Text="update" OnClick="gv_RowEditing"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Note">
<ItemTemplate>
<asp:TextBox ID="note" runat="server" Text='<%#Eval("Note")%>' onfocus="this.style.color='red'" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="max">
<ItemTemplate>
<asp:TextBox ID="maxtxt" runat="server" Text='<%#Eval("prix max")%>' onfocus="this.style.color='red'"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="min" >
<ItemTemplate>
<asp:TextBox ID="mintxt" runat="server" Text='<%#Eval("prix min")%>' onfocus="this.style.color='red'"/>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowSelectButton="True" />
</Columns>
<EditRowStyle BorderColor="Yellow" Font-Underline="True" ForeColor="#FF3300" />
</asp:GridView>
I need to add an alert when i click into the button savebtn, if maxtxt value is less than mintxt value , an warning message appears.
How can i do this?
What is the differents ways to add an alert message to an aspx page?
Use the OnClientClick event to call a Javascript method to validate your fields.
<asp:Button ID="Savebtn" runat="server" Text="update" OnClick="gv_RowEditing"
OnClientClick="if ( ! ValidateFields()) return false;"/>
Your javascript method: (Not 100% sure of syntax but you get the idea)
function ValidateFields() {
var maxtxt = document.getElementById("<%=maxtxt.ClientID%>").Value;
var mintxt = document.getElementById("<%=mintxt.ClientID%>").Value;
if ( maxtxt < mintxt ) {
alert("This is bad");
return false;
}
return true;
}
Use the OnClientClick function of the Button to specify some JavaScript to run before the postback occurs.
<asp:Button ID="Button1" runat="server" Text="Delete" OnClientClick='MyFunction();' OnClick="Button1_Click" />
function MyFunction()
{
var maxtxt = document.getElementById("<%=maxtxt.ClientID%>").Value;
var mintxt = document.getElementById("<%=mintxt.ClientID%>").Value;
if ( maxtxt < mintxt ) {
alert("You did something wrong!");
}
}
Often, you simply want to confirm some action on the client side before it gets to the server side
<asp:Button ID="Button1" runat="server" Text="Delete" OnClientClick='return confirm("Are you sure you want to delete this item?");' OnClick="Button1_Click" />
You can combine the two...
<asp:Button ID="Button1" runat="server" Text="Delete" OnClientClick='return MyFunction();' OnClick="Button1_Click" />
function MyFunction()
{
var maxtxt = document.getElementById("<%=maxtxt.ClientID%>").Value;
var mintxt = document.getElementById("<%=mintxt.ClientID%>").Value;
if ( maxtxt < mintxt ) {
return confirm("Are you sure you want to do that");
}
return true;
}
<asp:Button ID="Savebtn" runat="server" Text="update" OnClick="gv_RowEditing"/>
function gv_RowEditing(){
if(parseInt($('#maxTxt').val()) < parseInt($('#minTxt').val())){
alert("you message");
}
}
or
$("#Savebtn").click(function() {
if(parseInt($('#maxTxt').val()) < parseInt($('#minTxt').val())){
alert("you message");
}
});
This is using jquery.
Define your gridview as follows:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:HiddenField ID="Ref" runat="server" value='<%#Eval("Ref")%>' ></asp:HiddenField>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Button ID="Savebtn" runat="server" Text="update" OnClick="gv_RowEditing"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Note">
<ItemTemplate>
<asp:TextBox ID="note" runat="server" Text='<%#Eval("Note")%>' onfocus="this.style.color='red'" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="max">
<ItemTemplate>
<asp:TextBox ID="maxtxt" maxtxt="1" runat="server" Text='<%#Eval("prix max")%>' onfocus="this.style.color='red'"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="min" >
<ItemTemplate>
<asp:TextBox ID="mintxt" mintxt="1" runat="server" Text='<%#Eval("prix min")%>' onfocus="this.style.color='red'"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button CommandName="Update" Text="Update" OnClientClick="return Validate();" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BorderColor="Yellow" Font-Underline="True" ForeColor="#FF3300" />
</asp:GridView>
Then include the following js (using jquery):
function Validate(){
var max = $("input[maxtxt]").val();
var min = $("input[mintxt]").val();
if (maxtxt < mintxt){
alert("Something wrong!!");
return false;
}
else{
return true;
}
}

Bind Dropdown list in Gridview footer which is in Tab Control

I am using ASP.NET and Entity Framework and Tab control of AJAX
I have a dropdown list control in gridview which is in TAB control Am not able to bind dropdown list control.
Tab Control --> Gridview --> Dropdown list
My ASP.NET Code is
<ajax:TabContainer ID="TabContainer2" runat="server" CssClass="fancy fancy-green">
<ajax:TabPanel ID="TabPanel1" runat="server">
<HeaderTemplate>
College Toppers
</HeaderTemplate>
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server">
<div>
<asp:GridView ID="GridView1" DataKeyNames="TL_ID" runat="server"
AutoGenerateColumns="False" CssClass="Gridview" ShowFooter="True" OnRowDataBound="GRVToppers_RowDataBound">
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:ImageButton ID="imgbtnUpdate" CommandName="Update" runat="server" ImageUrl="~/Admin/Images/update.jpg" ToolTip="Update" Height="20px" Width="20px" /><asp:ImageButton ID="imgbtnCancel" runat="server" CommandName="Cancel" ImageUrl="~/Admin/Images/Cancel.jpg" ToolTip="Cancel" Height="20px" Width="20px" />
</EditItemTemplate>
<FooterTemplate>
<asp:ImageButton ID="imgbtnAdd" runat="server" ImageUrl="~/Admin/Images/AddNewitem.jpg" CommandName="AddNew" Width="30px" Height="30px" ToolTip="Add new User" ValidationGroup="validaiton" />
</FooterTemplate>
<ItemTemplate>
<asp:ImageButton ID="imgbtnEdit" CommandName="Edit" runat="server" ImageUrl="~/Admin/Images/Edit.jpg" ToolTip="Edit" Height="20px" Width="20px" /><asp:ImageButton ID="imgbtnDelete" CommandName="Delete" runat="server" ImageUrl="~/Admin/Images/delete.jpg" ToolTip="Delete" Height="20px" Width="20px" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Topper List No">
<EditItemTemplate>
<asp:Label ID="lblEditTpid" runat="server" Text='<%#Eval("TL_ID") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblShowTpid" runat="server" Text='<%#Eval("TL_ID") %>' />
</ItemTemplate>
<ControlStyle Width="10px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Department Name">
<EditItemTemplate>
<asp:DropDownList ID="ddlEditDeptname" runat="server" Width="90" DataTextField='<%#Bind("DEPT_NAME") %>' DataValueField='<%#Bind("DEPT_ID") %>' AppendDataBoundItems="true"></asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddladdnewDeptname" runat="server" Width="90" DataTextField='<%#Bind("DEPT_NAME") %>' DataValueField='<%#Bind("DEPT_ID") %>' AppendDataBoundItems="True"></asp:DropDownList>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblShowDeptname" runat="server" Text='<%#Eval("DEPT_NAME") %>' Width="90" />
</ItemTemplate>
<ControlStyle Width="30px" />
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="#61A6F8" Font-Bold="True" ForeColor="White"></HeaderStyle>
</asp:GridView>
</div>
</asp:Panel>
</ContentTemplate>
</ajax:TabPanel>
</ajax:TabContainer>
==================
My C# code is
protected void GRVToppers_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
var dept = from n in ecme.DEPT_MASTER
select new { n.DEPT_ID, n.DEPT_NAME };
DropDownList ddl = null;
if (e.Row.RowType == DataControlRowType.Footer)
{
ddl = e.Row.FindControl("ddladdnewDeptname") as DropDownList;
int cnt = 0;
cnt = dept.Count();
ListItem[] items = new ListItem[cnt];
for (int i = 0; i < cnt; i++)
{
items[i] = new ListItem("DEPT_NAME", "DEPT_ID");
}
}
}
catch (Exception)
{ }
}
========================
You can do this very easily...
Remove
DataTextField='<%#Bind("DEPT_NAME") %>' DataValueField='<%#Bind("DEPT_ID") %>' AppendDataBoundItems="True"
and
DataTextField='<%#Bind("DEPT_NAME") %>' DataValueField='<%#Bind("DEPT_ID") %>' AppendDataBoundItems="true"
from aspx code
and Make changes in
protected void GRVToppers_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
var dept = from n in ecme.DEPT_MASTER
select new { n.DEPT_ID, n.DEPT_NAME };
DropDownList ddl = (DropDownList)e.Row.FindControl("ddladdnewDeptname");
ddl.DataTextField = "DEPT_NAME";
ddl.DataValueField = "DEPT_ID";
ddl.DataSource = dept.ToList();
ddl.DataBind();
ddl.Items.Insert(0, "--Select Department--");
}
}
100% sure this 'll work...

Categories