I am trying to create my own online quiz website using ASP C#.
I tried to bind the question from database into gridview and set the page size of the gridview to 1.
And then I tried to pull the answers option (4 option) into radioButton.
But when I tried to move from the 1 page of gridview to another page, the checked value lost. I know thats because of when we changed the gridview page, it will do a postback.
My Questions are:
Why I can't access my RadioButton from CodeBehind? Is it because of inside the Updatepanel ?
Is it possible if we want to do a page index change in gridview without postback? Or,
is there another option to make my RadioButton checked value not lost when changing to the next page (next question) ?
here are my code :
**quiz.aspx :**
<asp:UpdatePanel ID="upd1" runat="server">
<ContentTemplate>
<asp:GridView ID="grdquestions" runat="server" EnableViewState="true" EnableSortingAndPagingCallbacks="false" OnPageIndexChanging="grdquestions_PageIndexChanging" AutoGenerateColumns="false" DataKeyNames="QuestionId" Width="100%" AllowPaging="True" AllowCustomPaging="False" PageSize="1" ViewStateMode="Enabled">
<Columns>
<asp:TemplateField HeaderText="DOJO eQuiz">
<ItemTemplate>
<table class="tableclass" id='<%#Eval("QuestionId") %>'>
<tr>
<td><b>Question : <%#Eval("Question") %></b>
<asp:HiddenField ID="hdnquestionId" runat="server" />
</td>
</tr>
<tr>
<td>
<table>
<tr style="margin-top: 10px;">
<td>
<table class="tblOptions">
<tr>
<td>
<asp:RadioButton ID="rdOption1" AutoPostBack="true" runat="server" Text='<%#Eval("Option1") %>' GroupName="chcbox" />
</td>
</tr>
<tr>
<td>
<asp:RadioButton ID="rdOption2" runat="server" AutoPostBack="true" Text='<%#Eval("Option2") %>' GroupName="chcbox" />
</td>
</tr>
<tr>
<td>
<asp:RadioButton ID="rdOption3" runat="server" AutoPostBack="true" Text='<%#Eval("Option3") %>' GroupName="chcbox" />
</td>
</tr>
<tr>
<td>
<asp:RadioButton ID="rdOption4" runat="server" Text='<%#Eval("Option4") %>' GroupName="chcbox" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbquestionstatus" runat="server"></asp:Label>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle HorizontalAlign="Center" CssClass="GridPager" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
**quiz.aspx.cs**
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] == null)
{
Response.Redirect("Login.aspx");
}
else
{
if (!Page.IsPostBack)
{
BindGrid();
}
else
{
}
}
}
public void BindGrid()
{
var sess = Session["username"].ToString();
string a = sess.Substring(sess.Length - 1);
SqlDataAdapter adp = new SqlDataAdapter("select * from dojoquiz order by " + a + "", ConfigurationManager.ConnectionStrings["dashboardConnectionString"].ToString());
adp.Fill(dt);
grdquestions.DataSource = dt;
grdquestions.DataBind();
}
protected void grdquestions_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
RadioButtonList rdlstOptions = (RadioButtonList)e.Row.FindControl("rdlstOptions");
HiddenField hdnquestionId = (HiddenField)e.Row.FindControl("hdnquestionId");
if (rdlstOptions != null && hdnquestionId != null)
{
DataRow[] result = dt.Select("questionid=" + (Convert.ToInt32(hdnquestionId.Value)));
DataView view = new DataView();
view.Table = dt;
view.RowFilter = "questionid=" + (Convert.ToInt32(hdnquestionId.Value));
if (view.Table.Rows.Count > 0)
{
DataTable dt1 = new DataTable();
dt1 = view.ToTable();
}
}
}
}
protected void grdquestions_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grdquestions.PageIndex = e.NewPageIndex;
this.BindGrid();
}
Thank you for any help and suggestions.
If the sql query is not change, then don't do DataBind() on post back, but you still need to give him the data source to get the data. So your code must be as:
protected void Page_Load(object sender, EventArgs e)
{
BindGrid();
}
public void BindGrid()
{
var sess = Session["username"].ToString();
string a = sess.Substring(sess.Length - 1);
SqlDataAdapter adp = new SqlDataAdapter("select * from dojoquiz order by " + a + "", ConfigurationManager.ConnectionStrings["dashboardConnectionString"].ToString());
adp.Fill(dt);
grdquestions.DataSource = dt;
if (!Page.IsPostBack)
grdquestions.DataBind();
}
Its not possible with out post back to change page or do thinks on GridView, but if you make it correct this is not an issue.
Related
I have labels in a ListView that display the size and finish of an object (an SKU). I would like to change the color of the font of those labels if that particular SKU is "in stock" (has a stockedid of 1). The stocked attribute is part of the table with the size and finish, but it is not displayed. I have looked for a solution, but nothing seems to be exactly what I want, since I am not displaying the information that is used to format the label.
Please "speak slowly" :-) as I'm a relative novice with this type of thing. (As is probably evident.)
<asp:ListView ID="ListViewSSD" runat="server" DataSourceID="SSD" >
<ItemTemplate>
<div id="sdoptions">
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("SKU", "ST.aspx?SKU={0}") %>' ImageUrl='<%# Eval("image1path", "Images/{0}") %>' ></asp:HyperLink>
<asp:Label ID="Label8" runat="server" Text='<%# Eval("length", "{0}\" x ") %>'></asp:Label>
<asp:Label ID="Label9" runat="server" Text='<%# Eval("width", "{0}\"") %>'></asp:Label>
<asp:Label ID="finishLabel" runat="server" cssClass="tinyprint" Text='<%# Eval("finish", "({0})") %>' />
</div>
</ItemTemplate>
</asp:ListView>
Thank you.
The "spot" or party room for formatting is in general the row data bind event.
This event lets you get your hands on each row, and do formatting.
so, for a repeater, listview, gridview etc.?
row data bind.
And note that "during" the data bind process, the full database row that you feed the data aware object (listview, gridview etc.) is avaible.
So, say I full out a listview with list of hotels, but for "active" hotels, I want say to highlight in blue. While the column "active" is in the data source, it not on the listview.
So then say this:
<asp:ListView ID="MyHotels" runat="server" DataKeyNames="ID"
OnItemDataBound="MyHotels_ItemDataBound" >
<ItemTemplate>
<tr style="">
<td><asp:Label ID="FirstNameLabel" runat="server" Text='<%# Eval("FirstName")%>' /> </td>
<td><asp:Label ID="LastNameLabel" runat="server" Text='<%# Eval("LastName") %>' /></td>
<td runat="server"><asp:Label ID="HotelNameLabel" runat="server" Text='<%# Eval("HotelName") %>' /></td>
<td><asp:Label ID="CityLabel" runat="server" Text='<%# Eval("City") %>' /></td>
<td style="width:350px">
<asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
</td>
<td style="text-align:center;vertical-align:middle">
<asp:Button ID="cmdView" runat="server" Text="View" class="btn"/>
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="itemPlaceholderContainer" runat="server"
class="table table-bordered table-hover">
<tr runat="server" style="">
<th runat="server">FirstName</th>
<th runat="server">LastName</th>
<th runat="server">HotelName</th>
<th runat="server">City</th>
<th runat="server">Description</th>
<th runat="server" style="text-align:center">View Hotel</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
My code to fill:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
LoadData();
}
void LoadData()
{
string strSQL = #"SELECT * FROM tblHotelsA ORDER BY HotelName";
DataTable rstData = new DataTable();
using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.TEST4))
{
using (SqlCommand cmdSQL = new SqlCommand(strSQL, conn))
{
cmdSQL.Connection.Open();
rstData.Load(cmdSQL.ExecuteReader());
}
}
MyHotels.DataSource = rstData;
MyHotels.DataBind();
}
And we get/see this:
We set the font bold (for any active hotel).
We set font italic, and also background of the cell to blue.
That code was this:
protected void MyHotels_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
DataRowView gData = e.Item.DataItem as DataRowView;
if ((bool)gData["Active"])
{
Label lblHotel = e.Item.FindControl("HotelNameLabel") as Label;
lblHotel.Font.Bold = true;
lblHotel.Font.Italic = true;
// get holdring cell
HtmlTableCell mycell = lblHotel.Parent as HtmlTableCell;
mycell.BgColor = "skyblue";
}
}
}
Based on Albert Kallal's answer, I was able to find another article that helped me to find an easy-for-me solution.
protected void ListViewSSD_ItemDataBound(object sender, ListViewItemEventArgs e)
{
Label Label8;
if (e.Item.ItemType == ListViewItemType.DataItem)
{
Label8 = (Label)e.Item.FindControl("Label8");
System.Data.DataRowView rowView = e.Item.DataItem as System.Data.DataRowView;
string stockstatus = rowView["stockedid"].ToString();
if (stockstatus == "1")
{
Label8.Font.Bold = true;
Label8.CssClass = "greenitalic";
}
}
Label Label9;
if (e.Item.ItemType == ListViewItemType.DataItem)
{
Label9 = (Label)e.Item.FindControl("Label9");
System.Data.DataRowView rowView = e.Item.DataItem as System.Data.DataRowView;
string stockstatus = rowView["stockedid"].ToString();
if (stockstatus == "1")
{
Label9.Font.Bold = true;
Label9.CssClass = "greenitalic";
}
}
}
I am trying to have the clicked on(selected) ListView item be highlighted. However what is currently happening is the last selected item is being highlighted instead.
Here is my asp.net code:
<asp:ListView ID="UsersListView" AutoPostBack="true" runat="server" OnSelectedIndexChanging="UsersListView_SelectedIndexChanging" OnSelectedIndexChanged="UsersListView_SelectedIndexChanged" >
<LayoutTemplate>
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr>
<td id="itemPlaceholder" runat="server">
</td>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server">
<td>
<asp:LinkButton ID="UserNameLinkButton" CommandName="Select" runat="server" Text='<%# Container.DataItem %>'/>
</td>
</tr>
</ItemTemplate>
<SelectedItemTemplate>
<tr runat="server" style="background-color: #336699;">
<td>
<asp:LinkButton ID="UserNameLinkButton" CommandName="Select" runat="server" Text='<%# Container.DataItem %>' BackgroundColor="#336699" ForeColor="White" />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
Here is my C# code beside:
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
List<string> users = new List<string>()
{
"Gary",
"Joe",
"Brian"
};
UsersListView.DataSource = users;
UsersListView.DataBind();
}
}
protected void UsersListView_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
{
UsersListView.SelectedIndex = e.NewSelectedIndex;
}
protected void UsersListView_SelectedIndexChanged(object sender, EventArgs e)
{
}
Thank you for your help.
You have to use OnCommand for link button or use ListViewItemCommand and pass Item.DisplayIndex as argument to linkButton attribute CommandArgument while you are selecting item and in your case when link button is not to highlight because you are focusing on selecting not over LinkButton.So do your code on Server Side for HighLight Item Button.
Aspx
<asp:ListView ID="UsersListView" AutoPostBack="true" runat="server" OnSelectedIndexChanged="UsersListView_SelectedIndexChanged" OnItemCommand="UsersListView_ItemCommand" OnSelectedIndexChanging="UsersListView_SelectedIndexChanging">
<LayoutTemplate>
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr>
<td id="itemPlaceholder" runat="server">
</td>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server">
<td>
<asp:LinkButton ID="UserNameLinkButton" CommandName="Select" OnCommand="UserNameLinkButton_Command" CommandArgument="<%# Container.DisplayIndex %>" runat="server" Text='<%# Container.DataItem %>'/>
</td>
</tr>
</ItemTemplate>
<SelectedItemTemplate>
<tr runat="server">
<td>
<asp:LinkButton ID="UserNameLinkButton" CommandName="Select" CommandArgument="<%# Container.DisplayIndex %>" runat="server" Text='<%# Container.DataItem %>' ForeColor="White" />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
cs(Code)
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<string> users = new List<string>()
{
"Gary",
"Joe",
"Brian"
};
UsersListView.DataSource = users;
UsersListView.DataBind();
}
}
int selectedIndex=0;
protected void UsersListView_ItemCommand(object sender, ListViewCommandEventArgs e)
{
foreach(var item in UsersListView.Items)
{
LinkButton reset=item.FindControl("UserNameLinkButton") as LinkButton;
reset.BackColor = System.Drawing.Color.White;
reset.ForeColor = System.Drawing.Color.Blue;
}
LinkButton linkButton = (e.Item.FindControl("UserNameLinkButton")) as LinkButton;
linkButton.BackColor = System.Drawing.ColorTranslator.FromHtml("#336699");
linkButton.ForeColor = System.Drawing.Color.White;
}
protected void UsersListView_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
{
}
protected void UsersListView_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void UserNameLinkButton_Command(object sender, CommandEventArgs e)
{
//you can also do work here for when one of link button give command.(clicked)
}
Tested
How to delete data from session datatable using button inside datalist?
This code is to display product added inside shopping cart and bremove button is used to remove that item from datalist
Front End Code
<asp:DataList ID="DataList1" runat="server" Width="100%" HorizontalAlign="Center">
<ItemStyle BorderStyle="Double" />
<ItemTemplate>
<center>
<table class="table" style="border-style: dashed; top: 211px; left: 23px; height: auto; table-layout: fixed; width: 100%;">
<tr>
<td>
<asp:Image ID="Pimg" runat="server" ImageUrl='<%# Eval("Pimg") %>' CssClass="img img-responsive" Height="140px" Width="240px" />
</td>
<td>
<asp:Label ID="Pname" runat="server" Text='<%# Eval("Pname") %>'></asp:Label>
</td>
<td>
<asp:Label ID="Pqty" runat="server" Text='<%# Eval("Pqty") %>'></asp:Label>
</td>
<td>
<asp:Label ID="Price" runat="server" Text='<%# Eval("Price") %>'></asp:Label>
</td>
<td>
<asp:Button ID="bremove" runat="server" Text="Remove" OnClick="bremove_Click" />
</td>
</tr>
</table>
</center>
</ItemTemplate>
</asp:DataList>
Back End Code
protected void bremove_Click(object sender, EventArgs e)
{
int index = DataList1.SelectedIndex;
DataTable dt = Session["AddToCard"] as DataTable;
dt.Rows[index].Delete();
porductlist = dt;
BindData();
Response.Redirect("Default.aspx");
}
public void BindData()
{
DataList1.DataSource = porductlist;
DataList1.DataBind();
}
Add AcceptChanges()
protected void bremove_Click(object sender, EventArgs e)
{
int index = DataList1.SelectedIndex;
DataTable dt = Session["AddToCard"] as DataTable;
dt.Rows[index].Delete();
dt.AcceptChanges();
DataList1.DataSource = dt;
DataList1.DataBind();
porductlist = dt;
BindData();
Response.Redirect("Default.aspx");
}
But you call BindData() AND redirect, redirecting is not necessary. Unless you want to go to another page in which case the BindData() is not necessary.
UPDATE
To get the correct row number, use a button with a Command, not a Click and send the row number as CommandArgument.
<asp:Button ID="bremove" runat="server" Text="Button" OnCommand="bremove_Command" CommandArgument='<%# Container.ItemIndex %>' />
protected void bremove_Command(object sender, CommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
}
Add a custom attribute (e.g. id of your db-entry) to your button:
<asp:Button ID="bremove" runat="server" Text="Remove" OnClick="bremove_Click" entry-id='<%# Eval("ID") %>' />
then in codebehind you can read out the attribute:
protected void bremove_Click(object sender, EventArgs e)
{
string id = ((Button)sender).Attributes["data-id"];
// .. your code ..
}
please reassign update dt into session variable to update Session values .
protected void bremove_Click(object sender, EventArgs e)
{
int index = DataList1.SelectedIndex;
DataTable dt = Session["AddToCard"] as DataTable;
dt.Rows[index].Delete();
porductlist = dt;
Session["AddToCard"]= dt
BindData();
Response.Redirect("Default.aspx");
}
public void BindData()
{
DataList1.DataSource = porductlist;
DataList1.DataBind();
}
Below is code of a GirdView in which i've taken a PagerTemplate which is working fine except the attribute PagerSettings-PageButtonCount="3".
I wanted to display only three page numbers at a time which is normally accomplished by the PageButtonCount attribute.
Asp.Net
<asp:GridView
id="grdMovies"
DataSourceID="srcMovies"
AllowPaging="true"
PageSize="3"
Runat="server"
PagerSettings-PageButtonCount="3"
OnDataBound="grdMovies_DataBound">
<PagerTemplate>
<table>
<tr>
<td>
<asp:LinkButton
id="lnkPrevious"
Text="< Prev"
CommandName="Page"
CommandArgument="Prev"
ToolTip="Previous Page"
Runat="server" />
</td>
<td>
<asp:Menu
id="menuPager"
Orientation="Horizontal"
OnMenuItemClick="menuPager_MenuItemClick"
CssClass="menu"
Runat="server" />
</td>
<td>
<asp:LinkButton
id="lnkNext"
Text="Next >"
CommandName="Page"
CommandArgument="Next"
ToolTip="Next Page"
Runat="server" />
</td>
</tr>
</table>
</PagerTemplate>
</asp:GridView>
C# Code
<script runat="server">
protected void grdMovies_DataBound(object sender, EventArgs e)
{
Menu menuPager = (Menu)grdMovies.BottomPagerRow.FindControl("menuPager");
for (int i = 0; i < grdMovies.PageCount; i++)
{
MenuItem item = new MenuItem();
item.Text = (i + 1).ToString();
item.Value = i.ToString();
if (grdMovies.PageIndex == i)
item.Selected = true;
menuPager.Items.Add(item);
}
}
protected void menuPager_MenuItemClick(object sender, MenuEventArgs e)
{
grdMovies.PageIndex = Int32.Parse(e.Item.Value);
}
</script>
How can i achieve this.
Thanks..
I guess you need to add this property in your gridview
PagerSettings-Mode="NumericFirstLast"
I'm new to aspnet programming and need some help. I've been scouring the internet and can't find a solution to my problem. I basically need a way to have a textbox show only when it's corresponding checkbox is checked. The textboxes and checkboxes are part of an inner datalist; the controls have to be databound. I've tried JQuery and couldn't get it to work, so now I'm trying AJAX with the UpdatePanel--still not working right. Below is my current code which resides in a user control. I basically included code that pertains to the checkboxes/textboxes. The script manager is referenced in the master page. Any help would be appreciated.
Thanks in advance!
HTML ----->
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DataList ID="outerDataList" runat="server" OnItemDataBound="outerRep_ItemDataBound">
<ItemTemplate>
<div id="div1" runat="server" visible='<%# ((string)Eval("Code")) != "BABRB" %>'>
<asp:Label ID="lblBABProdType" Font-Size="Medium" Font-Bold="true" runat="server" Text='<%# Eval("Name") %>' style="padding-left:20px" />
<asp:DataList ID="innerDataList" runat="server" RepeatColumns="3" DataKeyField="ProductID" >
<ItemTemplate>
<div id="div4" runat="server" visible='<%# ((string)Eval("ProductCode")) == "BABBE" %>'>
<table ID="table4" runat="server" align="left" width="80%" style="margin-left:30px; font-size:smaller">
<tr>
<td width="3%">
<asp:CheckBox ID="bevCheckBox" runat="server" AutoPostBack="true"
OnCheckedChanged="chkBox_CheckedChanged"/>
</td>
<td align="left" width="7%">
<asp:ImageButton ID="bevImgBtn" runat="server" width="40" height="40" align="middle"
ImageUrl='<%# "~/ProductImages/"+Eval("Image1FileName").ToString() %>'
OnClick="ImgBtn_Click" CommandArgument='<%# Eval("ProductID") %>'/>
</td>
<td valign="middle" width="70%">
<span class="ProductName">
<asp:LinkButton ID="bevLnkBtn" runat="server" OnClick="LnkBtn_Click" CssClass="BABProductName"
CommandArgument='<%# Eval("ProductID") %>'>
<%# DataBinder.Eval(Container.DataItem, "Name")%>
<br /></asp:LinkButton>
</span>
<span class="ProductPrice">
<%# DataBinder.Eval(Container.DataItem, "Price", "{0:c}")%>
</span
<asp:TextBox ID="bevQtyTxtBox" runat="server" Text="Qty: " Font-Size="XX-Small"
Width="40px" ViewStateMode="Disabled"/>
</td>
</tr>
</table>
</div>
<div id="div5" runat="server" visible='<%# ((string)Eval("ProductCode")) == "BABFO" %>' >
<table ID="table5" runat="server" align="left" width="80%" style="margin-left:30px; font-size:smaller">
<tr>
<td width="3%">
<asp:CheckBox ID="foodCheckBox" runat="server" AutoPostBack="true"
OnCheckedChanged="chkBox_CheckedChanged"/>
</td>
<td align="left" width="7%">
<asp:ImageButton ID="foodImgBtn" runat="server" width="40" height="40" align="middle"
ImageUrl='<%# "~/ProductImages/"+Eval("Image1FileName").ToString() %>'
OnClick="ImgBtn_Click" CommandArgument='<%# Eval("ProductID") %>'/>
</td>
<td valign="middle" width="70%">
<span class="ProductName">
<asp:LinkButton ID="foodLnkBtn" runat="server" OnClick="LnkBtn_Click" CssClass="BABProductName"
CommandArgument='<%# Eval("ProductID") %>'>
<%# DataBinder.Eval(Container.DataItem, "Name")%>
<br /></asp:LinkButton>
</span>
<span class="ProductPrice">
<%# DataBinder.Eval(Container.DataItem, "Price", "{0:c}")%>
</span>
<asp:TextBox ID="foodQtyTxtBox" runat="server" Text="Qty: " Font-Size="XX-Small"
Width="40px" ViewStateMode="Disabled"/>
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:DataList>
</div>
<br />
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>
CODE BEHIND ----->
protected void Page_Load(object sender, EventArgs e)
{
PopulateData();
}
private void PopulateData()
{
// Retrieve list of products
string categoryID = Request.QueryString["BABCategoryID"];
// set the stored procedure name
SqlConnection sqlConn = new SqlConnection(ChocolateExpConfiguration.DbConnectionString);
SqlCommand sqlComm = new SqlCommand("GetBABProductsInCategory", sqlConn);
sqlComm.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adptr = new SqlDataAdapter(sqlComm);
sqlComm.Parameters.AddWithValue("#BABCategoryID", categoryID);
DataSet ds = new DataSet();
adptr.Fill(ds);
ds.Relations.Add(new DataRelation("CodeRelation", ds.Tables[0].Columns["Code"], ds.Tables[1].Columns["ProductCode"]));
outerDataList.DataSource = ds.Tables[0];
outerDataList.DataBind();
}
protected void outerRep_ItemDataBound(object sender, DataListItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
{
DataRowView drv = e.Item.DataItem as DataRowView;
DataList innerDataList = (DataList)e.Item.FindControl("innerDataList");
innerDataList.DataSource = drv.CreateChildView("CodeRelation");
innerDataList.DataBind();
}
}
protected void chkBox_CheckedChanged(object sender, EventArgs e)
{
foreach (DataListItem parentItem in outerDataList.Items)
{
//Find nested items(DataList) of parent Datalist
DataList innerDataList = (DataList)parentItem.FindControl("innerDataList");
foreach (DataListItem childItem in innerDataList.Items)
{
CheckBox bevCheckBox = (CheckBox)childItem.FindControl("bevCheckBox");
CheckBox foodCheckBox = (CheckBox)childItem.FindControl("foodCheckBox");
TextBox bevQtyTxtBox = (TextBox)childItem.FindControl("bevQtyTxtBox");
TextBox foodQtyTxtBox = (TextBox)childItem.FindControl("foodQtyTxtBox");
if ((bevCheckBox.Checked == true) || (foodCheckBox.Checked == true))
{
bevQtyTxtBox.Visible = true;
foodQtyTxtBox.Visible = true;
}
else
{
bevQtyTxtBox.Visible = false;
foodQtyTxtBox.Visible = false;
}
UpdatePanel1.Update();
}
}
}*
protected void EnableTextBox()
{
int count = int.Parse(GridView1.Rows.Count.ToString());
for (int i = 0; i < count; i++)
{
CheckBox cb = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
CheckBox cb1 = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox2");
CheckBox cb2 = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox3");
TextBox tb = (TextBox)GridView1.Rows[i].Cells[4].FindControl("txtration");
TextBox tb1 = (TextBox)GridView1.Rows[i].Cells[5].FindControl("txtjob");
TextBox tb2 = (TextBox)GridView1.Rows[i].Cells[6].FindControl("txtaadhar");
if (cb.Checked == true)
{
tb.Visible = true;
}
else
{
tb.Visible = false;
}
if (cb1.Checked == true)
{
tb1.Visible = true;
}
else
{
tb1.Visible = false;
}
if (cb2.Checked == true)
{
tb2.Visible = true;
}
else
{
tb2.Visible = false;
}
}
}
in checkedchanged event
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
EnableTextBox();
}