i have a gridview to insert values to the database dynamically..
i have one dropdownlist for selecting employee id and one textbox for getting personnel details...
dropdownlist values are getting from database using select query and binding those values into dropdownlist which exists in gridview
personnel details text box values entered by user for each employee
if one employee selects from dropdownlist and inserts details into textbox after submitting his details his empid must hide in that dropdownlist...for not getting multiple rows about the employee.
<asp:TemplateField HeaderText="EMPID>
<ItemTemplate>
<asp:DropDownList ID="empid" runat="server" Width="100px">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="EMPID>
<ItemTemplate>
<asp:TextBox id="txtbox" runat="server" width="100px"></asp:TextBox>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="Add_Details" runat="server" Text="Add Details" OnClick="Addhour_Click"/>
</FooterTemplate>
</asp:TemplateField>
in the above empid is the dropdownlist which binds data from database...
and txtbox is used to get the personneldetails about the empid selected from dropdownlist empid...
after selecting one id from dropdownlist and entering some data into text if we click to add details button the details are storing into database correctly and inserting another row into gridview..
but again already inserted empid also displaying in that dropdownlist...
how to remove that item from dropdownlist after inserting data into database for perticular emp..id.. thanks in advance.. please help me to solve this problem...
If you want to really hide id from dropdown then you can add field (may be bit datatype and name as addedRecord) in the table from where Id is coming. set that field if record is added and bind drop down with only ids that are not set. Otherwise you can check in database before adding personnel info, if that exists then don't insert it.
Use your postback correctly Give this in your pageload()
if(!postback)
{
ddlbindcode();//dropdownlist bind query
}
Related
I have one query which is related to get focus in itemfield of Textbox in gridview. Based on checkbox selection populating different number of textBoxes and after entered data in last textbox and making webservice call based on response populating gridview with itemField(textboxes).
The scenario is explaining below.
CheckBox(Unchecked): False
Number of text boxes(ID): 1
CheckBox(Checked): True
Number of text boxes(ID, AccNo, Price): 3
After entered values in last textboxes, make webservice call and filling gridview with data but it's not get focus of first textbox in GridView.
<asp:TemplateField>
<HeaderTemplate>
<p>Paid Amount</p>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtAmnt" runat="server" TabIndex="1"
onkeypress="return isNumberKey(event,this)" onblur="calAmount(event,this)" Text='<%# Eval("PaidAmount") %>'>
</asp:TextBox>
</ItemTemplate>
I have not any event related gridview making like, rowBound, CommandView. Could you please show me a way related this.
Thank you so much in advance.
I have a grid view in a asp page which have a hyperlink field,say,CustomerID which navigates user to various webpages. The value of the CustomerID in the grid view can have duplicate values. So, what I want is how to record all the clicked values in the CustomerID or the hyperlink?
Please suggest solution such that the solution is viable for multiple hyperlink column in gridview each navigation to different webpage.
You can use combination of gridview bind columns and pass them as parameters in url and retrieve in other page as Request.QueryString[] collection.
Eg
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink runat="server" NavigateUrl='<%# string.Format("~/Details.aspx?CustomerID={0}&Name={1}&Country={2}",
HttpUtility.UrlEncode(Eval("CustomerID").ToString()), HttpUtility.UrlEncode(Eval("Name").ToString()), HttpUtility.UrlEncode(Eval("Country").ToString())) %>'
Text="View Details" />
</ItemTemplate>
</asp:TemplateField>
I have a Grid view, whenever I select 1st dropdownlist i.e. subject i want to bind related teachers name on second dropdownlist only one subject and teacher will updated dropdownlist is inside itemtemplate.
eg
<asp:TemplateField>
<HeaderTemplate>
Friday
</HeaderTemplate>
<ItemTemplate>
<asp:DropDownList ID="ddlSubjectFr" runat="server">
</asp:DropDownList>
<br />
<asp:DropDownList ID="ddlTeacherFr" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
If u want u change the Drop down list value of second based on first Drop down list selected value.. that should write in selected Index changed event with auto post back = "true"
I have displayed some fields in grid view, Now i want to select a row and i want to display all field from sql server in to a web form, after displaying the data in respective controls(textbox, dropdown), i want to update it.
How i can redirect the page to new webpage after selecting the respective row from grid view (Using primary key). and how the data will be pass on page load in respective fields so i could able to update it by using update query.
As i new to ASP. Net. Please update me in detail. If possible please with code.
It would go something like this.
You will make a 'list' webform with all records containing the gridview
Make another webform called details
The gridview on list page will contain a hyperlink button field something like this
<asp:HyperLinkField Text="View Details" DataNavigateUrlFields="YourId" DataNavigateUrlFormatString="details.aspx?id={0}" />
(Notice I am just redirecting to the details page passing the field id with querystring.
Now, on details page you would just fetch the querystring value & query your database with a datareader & populate your details page.
Something like on page load
if(Request.QueryString["id"])!=null)
{
// Fetch respective item from database here & populate form fields
// Open connection(); execute datareader;populate form fields
}
Easiest way to do this:
<asp:GridView ID="grd" runat="server" autogeneratedcolumn="false">
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<%#Eval("ID")%>
<ItemTemplate>
<asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<%#Eval("ID")%>
<ItemTemplate>
<asp:TemplateField>
<asp:TemplateField HaderText="Edit">
<ItemTemplate>
<a href='EditData.aspx?ID=<%#Eval("ID")%>'>Edit</a>
</ItemTemplate>
<asp:TemplateField>
<asp:GridView>
EditData.aspx page will be used to edit the data. After receiving the Query-string Value,we can bind the data to the controls and then update the data after making changes.
Is there a way to get the index of the most recently inserted record that was bound to a datalist? My datalist is sorted, so my record is not the last one. I am trying to highlight the record that just got inserted, so I need to know where it is in the datalist.
This is in ASP .NET C#.
edit: I should probably rephrase my question. After I insert a record, I "re-get" my records and rebind the datalist to update it with the inserted record. Depending on what sort mode it is on, the newly added record can be anywhere in the list.
I hope if this will work for you.
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
REF: Autonumbering ASP.NET grid controls