|
I'm getting the following error: No overload for 'gvKeyPersonnel_RowUpdating' matches delegate 'System.EventHandler'
|
|
|
|
|
Norris Chappell wrote: Should I I removed this too? cmd.Parameters.Clear(); Since you are not inside a loop anymore, you may want to remove that line. But that won't matter much as the SqlCommand is going to be disposed anyway (at the end of the using block).
Also, since you are not using the foreach anymore, you may want to remove its "{ }" braces as well, as they are forming an unnecessary code-block at the moment.
You have just been Sharapova'd.
|
|
|
|
|
GridViewRow row = gvKeyPersonnel.Rows[e.RowIndex]; is giving me this error:
it doesn't like the e.RowIndex
'System.Web.UI.WebControls.GridViewUpdatedEventArgs' does not contain a definition for 'RowIndex' and no extension method 'RowIndex' accepting a first argument of type 'System.Web.UI.WebControls.GridViewUpdatedEventArgs' could be found (are you missing a using directive or an assembly reference?)
|
|
|
|
|
If you are using GridViewUpdatedEventArgs e as a parameter to the gvKeyPersonnel_RowUpdating method/handler, then it's wrong. The method signature should look like this:
protected void gvKeyPersonnel_RowUpdating(object sender, GridViewUpdateEventArgs e) that is, you initially had it correct. Note that it's GridViewUpdateEventArgs in the parameter.
Don't get confused. The OnRowUpdating event that you already have should used to perform actual update (this you already have in place), where as the OnRowUpdated event I just suggested should be used to perform something "after" you have updated a row, like notify the user, rebind the grid, etc.
You have just been Sharapova'd.
|
|
|
|
|
Made that change but when I ran my code I got this error again: No overload for 'gvKeyPersonnel_RowUpdating' matches delegate 'System.EventHandler'
|
|
|
|
|
Hmm, not sure. Can you show your grid's markup and "gvKeyPersonnel_RowUpdating" method again?
You have just been Sharapova'd.
|
|
|
|
|
protected void gvKeyPersonnel_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = conn;
conn.Open();
GridViewRow row = gvKeyPersonnel.Rows[e.RowIndex];
cmd.CommandText = "UPDATE SP2010_EDCStaffing_AppDB.dbo.CMS_Key_Personnel SET Name = @Name, VDCIDIQ = @VDCIDIQ, VDCFFS = @VDCFFS, VDCHIM = @VDCHIM, VDCWEBHOSTING = @VDCWEBHOSTING, VDCCWF = @VDCCWF WHERE ID = @id";
cmd.Parameters.AddWithValue("@id", Convert.ToInt32(gvKeyPersonnel.DataKeys[row.RowIndex].Values[0]));
cmd.Parameters.AddWithValue("@Name", row.Cells[1].Text);
cmd.Parameters.AddWithValue("@VDCIDIQ", row.Cells[2].Text);
cmd.Parameters.AddWithValue("@VDCFFS", row.Cells[3].Text);
cmd.Parameters.AddWithValue("@VDCHIM", row.Cells[4].Text);
cmd.Parameters.AddWithValue("@VDCWEBHOSTING", row.Cells[5].Text);
cmd.Parameters.AddWithValue("@VDCCWF", row.Cells[6].Text);
cmd.ExecuteNonQuery();
}
conn.Close();
}
|
|
|
|
|
<asp:GridView runat="server" ID="gvKeyPersonnel"
AutoGenerateColumns="False" BackColor="White" BorderColor="#DEDFDE" DataKeyNames="ID"
BorderStyle="None" BorderWidth="1px" CellPadding="4" OnRowUpdating="gvKeyPersonnel_RowUpdating"
EnableModelValidation="True" ForeColor="Black" GridLines="Vertical">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:TextBox runat="server" text='<%#Eval("ID") %>' ID="txtID" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:TextBox runat="server" text='<%#Eval("Name") %>' ID="txtName" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="VDCIDIQ">
<ItemTemplate>
<asp:TextBox runat="server" text='<%#Eval("VDCIDIQ") %>' ID="txtVDCIDIQ" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="VDCFFS">
<ItemTemplate>
<asp:TextBox runat="server" text='<%#Eval("VDCFFS") %>' ID="txtVDCFFS" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="VDCHIM">
<ItemTemplate>
<asp:TextBox runat="server" text='<%#Eval("VDCHIM") %>' ID="txtVDCHIM" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="VDCWEBHOSTING">
<ItemTemplate>
<asp:TextBox runat="server" text='<%#Eval("VDCWEBHOSTING") %>' ID="txtVDCWEBHOSTING" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="VDCCWF">
<ItemTemplate>
<asp:TextBox runat="server" text='<%#Eval("VDCCWF") %>' ID="txtVDCCWF" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<br />
<asp:Button ID="Update" runat="server" onclick="gvKeyPersonnel_RowUpdating" Text="Update" />
|
|
|
|
|
You are using the same event handler for handling ButtonClick event, that's not going to work. GridView's OnRowUpdating requires GridViewUpdateEventArgs type of EventArgs where as a Button's click requires EventArgs . You might get away with casting, but I won't recommend that.
Also, I don't see any anything for handling the "Edit" operation. Note that, you generally have an Update on a grid only if you also have an Edit (AFAIK).
Have a look at this[^] example on MSDN. Also search for something like "ASP.NET GridView inline edit and update." That should clear things up.
All the best.
You have just been Sharapova'd.
|
|
|
|
|
Hi, I have finally got the edit, update and delete to work. However, for the update can you have more than 1 set statement with the update command? I want to thanks everyone for there help and comments.
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.UI.WebControls.WebParts;
namespace StaffingWebParts.keypernew
{
public partial class keypernewUserControl : UserControl
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLStaffingConn"].ConnectionString);
SqlCommand cmd = new SqlCommand();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
KeyPersonnel();
}
}
protected void KeyPersonnel()
{
conn.Open();
SqlCommand cmd = new SqlCommand("Select id, Name from CMS_Key_Personnel", conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
int count = ds.Tables[0].Rows.Count;
conn.Close();
if (ds.Tables[0].Rows.Count > 0)
{
gvKeyPersonnel.DataSource = ds;
gvKeyPersonnel.DataBind();
}
else
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
gvKeyPersonnel.DataSource = ds;
gvKeyPersonnel.DataBind();
int columncount = gvKeyPersonnel.Rows[0].Cells.Count;
lblmsg.Text = " No data found !!!";
}
}
protected void gvKeyPersonnel_RowEditing(object sender, GridViewEditEventArgs e)
{
gvKeyPersonnel.EditIndex = e.NewEditIndex;
KeyPersonnel();
}
protected void gvKeyPersonnel_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int id = Convert.ToInt32(gvKeyPersonnel.DataKeys[e.RowIndex].Value);
TextBox Name = (TextBox)gvKeyPersonnel.Rows[e.RowIndex].FindControl("txtName");
conn.Open();
SqlCommand cmd = new SqlCommand("update CMS_Key_Personnel set Name='" + Name.Text + "' where id=" + id, conn);
cmd.ExecuteNonQuery();
conn.Close();
lblmsg.Text = id + " Updated successfully........ ";
gvKeyPersonnel.EditIndex = -1;
KeyPersonnel();
}
protected void gvKeyPersonnel_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gvKeyPersonnel.EditIndex = -1;
KeyPersonnel();
}
protected void gvKeyPersonnel_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id = gvKeyPersonnel.DataKeys[e.RowIndex].Values["id"].ToString();
conn.Open();
SqlCommand cmd = new SqlCommand("delete from CMS_Key_Personnel where id=" + id, conn);
int result = cmd.ExecuteNonQuery();
conn.Close();
if (result == 1)
{
KeyPersonnel();
lblmsg.Text = id + " Deleted successfully....... ";
}
}
protected void gvKeyPersonnel_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string id = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "id"));
Button lnkbtnresult = (Button)e.Row.FindControl("ButtonDelete");
if (lnkbtnresult != null)
{
lnkbtnresult.Attributes.Add("onclick", "javascript:return deleteConfirm('" + id + "')");
}
}
}
protected void gvKeyPersonnel_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("AddNew"))
{
TextBox inid = (TextBox)gvKeyPersonnel.FooterRow.FindControl("inid");
TextBox inname = (TextBox)gvKeyPersonnel.FooterRow.FindControl("inname");
conn.Open();
SqlCommand cmd =
new SqlCommand(
"insert into CMS_Key_Personnel(id, name,) values('" + inid.Text + "', '" + inname.Text + "')", conn);
int result = cmd.ExecuteNonQuery();
conn.Close();
if (result == 1)
{
KeyPersonnel();
lblmsg.Text = inid.Text + " Added successfully...... ";
}
else
{
lblmsg.Text = inid.Text + " Error while adding row.....";
}
}
}
}
}
modified 14-May-15 21:42pm.
|
|
|
|
|
This one can be closed. Thanks to everyone that helped me get though this project.
|
|
|
|
|
how work class scheduling system by C#
|
|
|
|
|
Carefully.
But...We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
Try it yourself, you may find it is not as difficult as you think!
If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Class scheduling, you mean something like time table?
For your precise question, a precise answer is, that you are going to require a database (to store the time table in actual) and a program to run and check for the data (from database). Want me to explain more? Explain your question more.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Hello,
Before starting college two weeks ago I didn't even know what C# was; I had never worked with codes other than HTML customization on Tumblr and Wordpress.com.
An exercise I have for school is to create a program that asks for three numbers, the first an even number, the second an odd number, and the third a number that can be evenly divided by 42. (The exercise isn't graded.) We're practicing methods, and I feel like I have the entire program right, except for this one method that I can't seem to get to work, the Add3Numbers method.
What am I doing wrong?
The Add3Numbers() in bold at the end is the problem. The red line disappears if I insert random numbers – like Add3Numbers(1, 2, 3) – but the program still doesn't run? Without the numbers I get the error "method overload. Method has 0 arguments."
Sorry if some of the {} are out of position. I tried to make them in order, but, I did copy and paste this…
class Program
{
static void Main(string[] args)
{
int Input1 = 0;
int Input2 = 0;
int Input3 = 0;
Input1 = GetFirstInPutFromUser();
Input2 = GetSecondInputFromUser();
Input3 = GetThirdInputFromUser();
int Sum = Add3Numbers(Input1, Input2, Input3);
Console.WriteLine("The sum is " + Sum);
Console.ReadLine();
}
static int GetFirstInPutFromUser()
{
Console.WriteLine("Please enter an even number");
int FirstInput = Convert.ToInt32(Console.ReadLine());
bool FirstRepeat = true;
while (FirstRepeat)
{
if (FirstInput % 2 == 0)
{
return FirstInput;
GetSecondInputFromUser();
}
else
{
FirstRepeat = false;
Console.WriteLine("That number is not an even number. Please try again.");
GetFirstInPutFromUser();
}
} while (FirstRepeat);
}
static int GetSecondInputFromUser()
{
Console.WriteLine("Please enter an odd number");
int SecondInput = Convert.ToInt32(Console.ReadLine());
bool SecondRepeat = true;
while (SecondRepeat)
{
if (SecondInput % 2 >= 1)
{
return SecondInput;
GetThirdInputFromUser();
}
else
{
SecondRepeat = false;
Console.WriteLine("That is not an odd number. Please try again");
GetSecondInputFromUser();
}
} while (SecondRepeat);
}
static int GetThirdInputFromUser()
{
Console.WriteLine("Please enter a number evenly divisble by 42");
int ThirdInput = Convert.ToInt32(Console.ReadLine());
bool ThirdRepeat = true;
while (ThirdRepeat)
{
if ((ThirdInput / 42 == 1) || (ThirdInput / 42 == 2))
{
return ThirdInput;
Add3Numbers();
}
else
{
ThirdRepeat = false;
Console.WriteLine("That number is not evenly divisble by 42. Please try again");
GetThirdInputFromUser();
} while (ThirdRepeat);
}
static int Add3Numbers(int One, int Two, int Three)
{
int Return = One + Two + Three;
return Return;
}
}
}
|
|
|
|
|
The only declaration of Add3Numbers you have in that code is this:
static int Add3Numbers(int One, int Two, int Three)
{
int Return = One + Two + Three;
return Return;
} And you only use it twice, once in your Main method:
int Sum = Add3Numbers(Input1, Input2, Input3);
And once in your GetThirdInputFromUser metyhod:
Add3Numbers();
The first use is fine: the method you declare requires three integers as parameters (that is called it's Signature) and your provide three integer values when you call it.
But the second call is different - you don't supply any parameters at all! So the system looks for methods called Add3Numbers, and can only find one, which needs three integers, and says "No overload takes 0 parameters" (or similar).
It's a bit like applying for a passport: You need to supply a recent photo of yourself, a copy of your birth certificate, and a cheque for £72.50. If you supply all three "parameters" then teh passport issuing authority will send you a passport. If you don't supply any one of them, all you will get back is a rude letter!
The passport office only have a Signature that want's three parameters, they don't define a method signature than has none!
There is also the fun that it couldn't be executed anyway:
if ((ThirdInput / 42 == 1) || (ThirdInput / 42 == 2))
{
return ThirdInput;
Add3Numbers();
} The return on the line above is not conditional; it will always exit the method at that point so any code after that will get an error saying "unreachable code detected".
And don't worry about the bracket alignment: once you get a clean compile, you can hold CTRL and press K, then (still holding CTRL) press D - Visual Studio will reformat the document for you.
But there are quite a lot of things you want to sort out first...your loop in GetThirdInputFromUser is rather odd as well:
while (ThirdRepeat)
{
if ((ThirdInput / 42 == 1) || (ThirdInput / 42 == 2))
{
return ThirdInput;
Add3Numbers();
}
else
{
ThirdRepeat = false;
Console.WriteLine("That number is not evenly divisble by 42. Please try again");
GetThirdInputFromUser();
} while (ThirdRepeat);
That's not the right syntax for a while loop: you don't need the "extra" while at the bottom:
while (ThirdRepeat)
{
if ((ThirdInput / 42 == 1) || (ThirdInput / 42 == 2))
{
return ThirdInput;
Add3Numbers();
}
else
{
ThirdRepeat = false;
Console.WriteLine("That number is not evenly divisble by 42. Please try again");
GetThirdInputFromUser();
} And let's be honest, that's not going to loop anyway because either you will use the return to exit, or you will set ThirdRepeat to false which will exit the loop anyway...
It all looks like "I panicked and wrote down anything" code instead of something you sat down and thought about - I'd suggest that you might be better off leaving this alone and starting from the beginning after thinking carefully about what you are trying to achieve.
The way I would do it is like this:
static void Main(string[] args)
{
int even = GetEvenNumber();
int odd = GetOddNumber();
int divisibleBy42 = GetDivisibleNumber(42);
Console.WriteLine("Even : {0}\nOdd : {1}\nDivisible : {2}", even, odd, divisibleBy42);
}
private static int GetEvenNumber()
{
return -1;
}
private static int GetOddNumber()
{
return -1;
}
private static int GetDivisibleNumber(int divisor)
{
return -1;
}
And then get each method in turn working before moving to the next.
I'd probably write a method that got a number from the user, and call it in each of those three then validate the number to see if it is acceptable...
Little hint on the last one - if you use the Modulus operator "%", you can check for divisibility very easily: if it returns 0, the number is exactly divisible...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi ;
1-day in the way I urge the base index with the following code automatically .
result : I get a script error.
2- webbrowser1.scripterrorssuppressed = true; I do not get to do when I command string error as above and wait out the succession button7_click icon () do not get any results when I call the incident.
3- button with Button7 and daily as if I click with the mouse, opening the daily index tabs .
I want to run automatically every time I click here. Waiting for your help in this regard.
private void gunluk_Click(object sender, EventArgs e)
{
HtmlElement aaa = webBrowser1.Document.GetElementById("rtsLink");
foreach (HtmlElement item in webBrowser1.Document.GetElementsByTagName("aa"))
{
if ((item.OuterHtml.ToLower().Contains("gunluk")) || (item.OuterHtml.ToLower().Contains("günlük")))
{
foreach (HtmlElement childItem in item.Children)
{
if (childItem.TagName == "A")
{
childItem.InvokeMember("Click");
break;
}
}
break;
}
}
}
private void button7_Click(object sender, EventArgs e)
{
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
HtmlElement selectF8 = webBrowser1.Document.GetElementById("ctl00_cphMaster_rtsDashboard").All[1];
for (int i = 0; i < selectF8.Children.Count; i++)
{
if ((selectF8.Children[i].InnerText.ToLower().IndexOf("gunluk endeks") > -1) || (selectF8.Children[i].InnerText.ToLower().IndexOf("günlük endeks") > -1))
{
try
{
selectF8.Children[i].InvokeMember("click");
break;
}
catch (Exception)
{
throw;
}
}
}
}
<div id="ctl00_cphMaster_rtsDashboard" class="RadTabStrip RadTabStrip_Outlook RadTabStripTop_Outlook rtsDashboard" style="width: 700px;">
<div class="rtsLevel rtsLevel1">
<ul class="rtsUL"><li class="rtsLI rtsFirst"><a class="rtsLink Home rtsSelected HomeSelected rtsHoverBefore" href="#"><span class="rtsIn"><span class="rtsTxt">Home</span></span></a></li><li class="rtsLI rtsLast"><a class="rtsLink rtsAfter" href="#"><span class="rtsIn"><span class="rtsTxt">Gunluk Endeks</span></span></a></li></ul>
</div><input id="ctl00_cphMaster_rtsDashboard_ClientState" name="ctl00_cphMaster_rtsDashboard_ClientState" type="hidden" autocomplete="off" value="{"selectedIndexes":["0"],"logEntries":[],"scrollState":{}}">
</div>
|
|
|
|
|
I can appreciate that English is not your first language but your post made no sense at all. I have no idea what you're trying to do and what the problem is.
|
|
|
|
|
GetElementsByTagName needs "DIV" or "INPUT" but not "aa"
Cannot understand your question more to help you
|
|
|
|
|
Hi everyone
Please I need your help, I have this exercise the problem is when i run it I get incorrect results
can someone please tell me what i am doing wrong.
I am trying to take the user input and multiply it by a constant I initialized to 7.
and when I enter input i used 5, it returns 371.
the answer is actually 35.
static void Main(String[] args)
{
Console.WriteLine("Enter your dogs age");
const int years = 7;
int dogAge = Console.Read();
int humanYears = dogAge * years;
Console.Write(humanYears);
Console.ReadKey();
|
|
|
|
|
If you input 5 then 35 would be the answer. I suggest you put a breakpoint and debug the code to see what is happening.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Thank ryan...for your input
|
|
|
|
|
What you are seeing here is the fact that the value you are getting out of Console.Read is not the value you think you're getting. The value that you are getting out of Console.Read here is 53. This is because 53 is the ASCII code for 5. In other words, you're getting a single character out of Console.Read which you are casting to an integer, which gives you the underlying ASCII value. What you want to do is something like this:
int dogAge;
if (!int.TryParse(Console.Read(), out dogAge)) return; This code does the check to see if the user has entered a number, and converts it to an integer if possible.
|
|
|
|
|
Thank peter i will try that.
|
|
|
|
|
|